var LiteGUI={root:null,content:null,panels:{},windows:[],undo_steps:[],modalbg_div:null,mainmenu:null,init:function(c){c=c||{};c.width&&c.height&&this.setWindowSize(c.width,c.height);this.container=null;c.container&&(this.container=document.getElementById(c.container));this.container||(this.container=document.body);if(c.wrapped){var a=document.createElement("div");a.style.position="relative";a.style.overflow="hidden";this.root=a;this.container.appendChild(a);this.content=a=document.createElement("div");
this.root.appendChild(a);this.root.classList.contains("fullscreen")&&window.addEventListener("resize",function(a){LiteGUI.maximizeWindow()})}else this.root=this.content=this.container;this.root.className="litegui-wrap fullscreen";this.content.className="litegui-maincontent";a=this.modalbg_div=document.createElement("div");this.modalbg_div.className="litemodalbg";this.root.appendChild(this.modalbg_div);a.style.display="none";c.menubar&&this.createMenubar();c.gui_callback&&c.gui_callback();window.addEventListener("beforeunload",
function(a){for(var c in LiteGUI.windows)LiteGUI.windows[c].close();LiteGUI.windows=[]})},trigger:function(c,a,b,e){var d=document.createEvent("CustomEvent");d.initCustomEvent(a,!0,!0,b);d.srcElement=e;c.dispatchEvent?c.dispatchEvent(d):c.__events&&c.__events.dispatchEvent(d);return d},bind:function(c,a,b){function e(c){if(c.addEventListener)c.addEventListener(a,b);else{if(!c.__events){var e=document.createElement("span");e.widget=c;Object.defineProperty(c,"__events",{enumerable:!1,configurable:!1,
writable:!1,value:e})}c.__events.addEventListener(a,b)}}if(!c)throw"Cannot bind to null";if(!a)throw"Event bind missing";if(!b)throw"Bind callback missing";c.constructor===String&&(c=document.querySelectorAll(c));if(c.constructor===NodeList||c.constructor===Array)for(var d=0;d<c.length;++d)e(c[d]);else e(c)},unbind:function(c,a,b){c.removeEventListener?c.removeEventListener(a,b):c.__events&&c.__events.removeEventListener&&c.__events.removeEventListener(a,b)},removeClass:function(c,a,b){b||(b=a,a=
"."+a);c=(c||document).querySelectorAll(a);for(a=0;a<c.length;++a)c[a].classList.remove(b)},add:function(c){this.content.appendChild(c.root||c)},remove:function(c){if(c){if(c.constructor===String)for(var a=document.querySelectorAll(c),b=0;b<a.length;++b)(c=a[b])&&c.parentNode&&c.parentNode.removeChild(c);if(c.constructor===Array||c.constructor===NodeList)for(b=0;b<c.length;++b)LiteGUI.remove(c[b]);else c.root&&c.root.parentNode?c.root.parentNode.removeChild(c.root):c.parentNode&&c.parentNode.removeChild(c)}},
getById:function(c){return document.getElementById(c)},createMenubar:function(){this.menubar=new LiteGUI.Menubar("mainmenubar");this.add(this.menubar)},setWindowSize:function(c,a){var b=this.root.style;if(c&&a)b.width=c+"px",b.height=a+"px",b.boxShadow="0 0 4px black",this.root.classList.remove("fullscreen");else{if(this.root.classList.contains("fullscreen"))return;this.root.classList.add("fullscreen");b.width="100%";b.height="100%";b.boxShadow="0 0 0"}LiteGUI.trigger(LiteGUI,"resized")},maximizeWindow:function(){this.setWindowSize()},
setCursor:function(c){this.root.style.cursor=c},isCursorOverElement:function(c,a){var b=c.pageX,e=c.pageY,d=a.getBoundingClientRect();return d?e>d.top&&e<d.top+d.height&&b>d.left&&b<d.left+d.width?!0:!1:!1},getRect:function(c){return c.getBoundingClientRect()},toClipboard:function(c,a){c&&c.constructor!==String&&(c=JSON.stringify(c));var b=null,e=!1;if(!a)try{document.queryCommandSupported("copy"),b=document.createElement("input"),b.type="text",b.style.opacity=0,b.value=c,document.body.appendChild(b),
b.select(),e=document.execCommand("copy"),console.log(e?"saved to clipboard":"problem saving to clipboard"),document.body.removeChild(b)}catch(d){b&&document.body.removeChild(b),console.warn("Oops, unable to copy using the true clipboard")}try{this._safe_cliboard=null,localStorage.setItem("litegui_clipboard",c)}catch(f){this._safe_cliboard=c,console.warn("cliboard quota excedeed")}},getLocalClipboard:function(){var c=localStorage.getItem("litegui_clipboard");!c&&this._safe_cliboard&&(c=this._safe_cliboard);
return c?"{"==c[0]?JSON.parse(c):c:null},addCSS:function(c){if(c)if(c.constructor===String){var a=document.createElement("style");a.type="text/css";a.innerHTML=c;document.getElementsByTagName("head")[0].appendChild(a)}else for(a in c)document.body.style[a]=c[a]},requireCSS:function(c,a){for("string"==typeof c&&(c=[c]);c.length;){var b=document.createElement("link");b.rel="stylesheet";b.type="text/css";b.href=c.shift(1);b.media="all";document.getElementsByTagName("head")[0].appendChild(b);0==c.length&&
(b.onload=a)}},request:function(c){var a=c.dataType||"text";"json"==a?a="text":"xml"==a?a="text":"binary"==a&&(a="arraybuffer",c.mimeType="application/octet-stream");var b=new XMLHttpRequest;b.open(c.data?"POST":"GET",c.url,!0);a&&(b.responseType=a);c.mimeType&&b.overrideMimeType(c.mimeType);c.nocache&&b.setRequestHeader("Cache-Control","no-cache");b.onload=function(a){a=this.response;if(200!=this.status)a="Error "+this.status,c.error&&c.error(a),LEvent.trigger(b,"fail",this.status);else{if("json"==
c.dataType)try{a=JSON.parse(a)}catch(e){if(c.error)c.error(e);else throw e;}else if("xml"==c.dataType)try{a=(new DOMParser).parseFromString(a,"text/xml")}catch(g){if(c.error)c.error(g);else throw g;}c.success&&c.success.call(this,a,this)}};b.onerror=function(a){c.error&&c.error(a)};a=new FormData;if(c.data)for(var e in c.data)a.append(e,c.data[e]);b.send(a);return b},requestText:function(c,a,b){return this.request({url:c,dataType:"text",success:a,error:b})},requestJSON:function(c,a,b){return this.request({url:c,
dataType:"json",success:a,error:b})},requestBinary:function(c,a,b){return this.request({url:c,dataType:"binary",success:a,error:b})},requireScript:function(c,a,b,e,d){if(!c)throw"invalid URL";c.constructor===String&&(c=[c]);var f=c.length,g=[],h;for(h in c){var k=document.createElement("script");k.num=h;k.type="text/javascript";k.src=c[h]+(d?"?version="+d:"");k.original_src=c[h];k.async=!1;k.onload=function(b){f--;g.push(this);f?e&&e(this.original_src,this.num):a&&a(g)};b&&(k.onerror=function(a){b(a,
this.original_src,this.num)});document.getElementsByTagName("head")[0].appendChild(k)}},requireScriptSerial:function(c,a,b){function e(){var f=document.createElement("script");f.type="text/javascript";f.src=c.shift(1);f.onload=function(f){c.length?(b&&b(c[0],c.length),e()):(d.push(this),a&&a(d))};document.getElementsByTagName("head")[0].appendChild(f)}"string"==typeof c&&(c=[c]);var d=[];e()},newDiv:function(c,a){return this.createElement("div",c,a)},createElement:function(c,a,b,e,d){c=document.createElement(c);
if(a){a=a.split(" ");for(var f=0;f<a.length;f++)"."==a[f][0]?c.classList.add(a[f].substr(1)):c.id="#"==a[f][0]?a[f].substr(1):a[f]}c.root=c;b&&(c.innerHTML=b);c.add=function(a){this.appendChild(a.root||a)};if(e)if(e.constructor===String)c.setAttribute("style",e);else for(f in e)c.style[f]=e[f];if(d)for(f in d)c.addEventListener(f,d[f]);return c},createListItem:function(c,a,b){var e=document.createElement("span");e.innerHTML=c;e=e.childNodes[0];if(a)for(var d in a)if(c=e.querySelector(d))c.innerText=
a[d];if(b)for(d in b)e.style[d]=b[d];return e},createButton:function(c,a,b,e){var d=document.createElement("button");d.className="litegui litebutton button";if(c){c=c.split(" ");for(var f=0;f<c.length;f++)"."==c[f][0]?d.classList.add(c[f].substr(1)):d.id="#"==c[f][0]?c[f].substr(1):c[f]}d.root=d;void 0!==a&&(d.innerHTML=a);b&&d.addEventListener("click",b);if(e)if(e.constructor===String)d.setAttribute("style",e);else for(f in e)d.style[f]=e[f];return d},getParents:function(c){for(var a=[];null!==(c=
c.parentElement);)c.nodeType===Node.ELEMENT_NODE&&a.push(elem);return a},newWindow:function(c,a,b,e){e=e||{};a=window.open("","","width="+a+", height="+b+", location=no, status=no, menubar=no, titlebar=no, fullscreen=yes");a.document.write("<html><head><title>"+c+"</title>");b=document.querySelectorAll("link[rel='stylesheet'],style");for(c=0;c<b.length;c++)a.document.write(b[c].outerHTML);if(e.scripts)for(b=document.querySelectorAll("script"),c=0;c<b.length;c++)b[c].src&&a.document.write(b[c].outerHTML);
a.document.write("</head><body>"+(e.content||"")+"</body></html>");a.document.close();return a},showModalBackground:function(c){LiteGUI.modalbg_div&&(LiteGUI.modalbg_div.style.display=c?"block":"none")},showMessage:function(c,a){a=a||{};a.title=a.title||"Attention";a.content=c;a.close="fade";var b=new LiteGUI.Dialog(a);a.noclose||b.addButton("Close",{close:!0});b.makeModal("fade");return b},popup:function(c,a){a=a||{};a.min_height=140;"string"==typeof c&&(c="<p>"+c+"</p>");a.content=c;a.close="fade";
var b=new LiteGUI.Dialog(a);a.noclose||b.addButton("Close",{close:!0});b.show();return b},alert:function(c,a){a=a||{};a.className="alert";a.title=a.title||"Alert";a.width=a.width||280;a.height=a.height||140;"string"==typeof c&&(c="<p>"+c+"</p>");LiteGUI.remove(".litepanel.alert");return LiteGUI.showMessage(c,a)},confirm:function(c,a,b){function e(b){b="yes"==this.dataset.value;d.close();a&&a(b)}b=b||{};b.className="alert";b.title=b.title||"Confirm";b.width=b.width||280;"string"==typeof c&&(c="<p>"+
c+"</p>");b.noclose=!0;var d=this.showMessage(c+"<button class='litebutton' data-value='yes' style='width:45%; margin-left: 10px'>Yes</button><button class='litebutton' data-value='no' style='width:45%'>No</button>",b);d.content.style.paddingBottom="10px";c=d.content.querySelectorAll("button");for(b=0;b<c.length;b++)c[b].addEventListener("click",e);c[0].focus();return d},prompt:function(c,a,b){function e(){var b=h.value;this.dataset&&"cancel"==this.dataset.value&&(b=null);g.close();a&&a(b)}b=b||{};
b.className="alert";b.title=b.title||"Prompt";b.width=b.width||280;"string"==typeof c&&(c="<p>"+c+"</p>");var d=b.value||"",f="<input type='text' value='"+d+"'/>";b.textarea&&(f="<textarea class='textfield' style='width:95%'>"+d+"</textarea>");b.noclose=!0;var g=this.showMessage(c+("<p>"+f+"</p><button class='litebutton' data-value='accept' style='width:45%; margin-left: 10px; margin-bottom: 10px'>Accept</button><button class='litebutton' data-value='cancel' style='width:45%'>Cancel</button>"),b);
c=g.content.querySelectorAll("button");for(b=0;b<c.length;b++)c[b].addEventListener("click",e);var h=g.content.querySelector("input,textarea");h.addEventListener("keydown",function(a){a||(a=window.event);a=a.keyCode||a.which;if("13"==a)return e(),!1;"29"==a&&g.close()},!0);h.focus();return g},choice:function(c,a,b,e){function d(c){c=a[this.dataset.value];g.close();b&&b(c)}e=e||{};e.className="alert";e.title=e.title||"Select one option";e.width=e.width||280;"string"==typeof c&&(c="<p>"+c+"</p>");for(var f in a)c+=
"<button class='litebutton' data-value='"+f+"' style='width:45%; margin-left: 10px'>"+(a[f].content||a[f])+"</button>";e.noclose=!0;var g=this.showMessage(c,e);g.content.style.paddingBottom="10px";c=g.content.querySelectorAll("button");for(f=0;f<c.length;f++)c[f].addEventListener("click",d);return g},downloadURL:function(c,a){var b=document.createElement("a");b.href=c;b.download=a;document.body.appendChild(b);b.click();document.body.removeChild(b)},downloadFile:function(c,a,b){if(a){b||(b=a.constructor===
String?"text/plain":"application/octet-stream");var e=null,e=a.constructor!==File&&a.constructor!==Blob?new Blob([a],{type:b}):a,d=URL.createObjectURL(e);a=document.createElement("a");a.setAttribute("href",d);a.setAttribute("download",c);a.style.display="none";document.body.appendChild(a);a.click();document.body.removeChild(a);setTimeout(function(){URL.revokeObjectURL(d)},6E4)}else console.warn("No file provided to download")},getUrlVars:function(){for(var c=[],a,b=window.location.href.slice(window.location.href.indexOf("?")+
1).split("&"),e=0;e<b.length;e++)a=b[e].split("="),c.push(a[0]),c[a[0]]=a[1];return c},getUrlVar:function(c){return LiteGUI.getUrlVars()[c]},focus:function(c){c.focus()},blur:function(c){c.blur()},draggable:function(c,a,b,e,d){function f(a){if("mousedown"==a.type){k||(l=(k=c.getClientRects()[0])?k.left:0,m=k?k.top:0);if(d&&!1==d(c,a))return a.stopPropagation(),a.preventDefault(),!1;g=a.clientX;h=a.clientY;document.addEventListener("mousemove",f);document.addEventListener("mouseup",f);b&&b(c,a);a.stopPropagation();
a.preventDefault();return!1}if("mouseup"==a.type)document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",f),e&&e(c,a);else if("mousemove"==a.type){var r=a.clientX-g,n=a.clientY-h;g=a.clientX;h=a.clientY;l+=r;m+=n;c.style.left=l+"px";c.style.top=m+"px"}}a=a||c;a.addEventListener("mousedown",f);a.style.cursor="move";var g=0,h=0,k=c.getClientRects()[0],l=k?k.left:0,m=k?k.top:0;c.style.position="absolute";c.style.left=l+"px";c.style.top=m+"px"},cloneObject:function(c,a){var b=
a||{},e;for(e in c)if("_"!=e[0]&&"jQuery"!=e.substr(0,6)){var d=c[e];if(null==d)b[e]=null;else if(!isFunction(d))if("number"==typeof d||"string"==typeof d)b[e]=d;else if(d.constructor==Float32Array)b[e]=Array.apply([],d);else if(isArray(d))b[e]&&b[e].constructor==Float32Array?b[e].set(d):b[e]=JSON.parse(JSON.stringify(d));else try{b[e]=JSON.parse(JSON.stringify(d))}catch(f){console.error(f)}}return b},safeName:function(c){return String(c).replace(/[\s\.]/g,"")},special_codes:{close:"&#10005;",navicon:"&#9776;",
refresh:"&#8634;",gear:"&#9881;",open_folder:"&#128194;",download:"&#11123;",tick:"&#10003;",trash:"&#128465;"},htmlEncode:function(c){var a=document.createElement("div");a.innerHTML=c;return a.innerText},htmlDecode:function(c){var a=document.createElement("div");a.innerText=c;return a.innerHTML},sizeToCSS:function(c){return void 0===c||null===c?null:c.constructor===String?c:0<=c?(c|0)+"px":"calc( 100% - "+Math.abs(c|0)+"px )"},getElementWindow:function(c){c=c.ownerDocument;return c.defaultView||
c.parentWindow},createDropArea:function(c,a,b,e){function d(a){c.addEventListener("dragexit",d);c.addEventListener("dragover",d);c.addEventListener("drop",f);a.stopPropagation();a.preventDefault();"dragenter"==a.type&&b&&b(a,this);"dragexit"==a.type&&e&&e(a,this)}function f(b){b.stopPropagation();b.preventDefault();c.removeEventListener("dragexit",d);c.removeEventListener("dragover",d);c.removeEventListener("drop",f);var e=void 0;a&&(e=a(b));if(e)return b.stopPropagation(),b.stopImmediatePropagation(),
!0}c.addEventListener("dragenter",d)}};Object.defineProperty(String.prototype,"template",{value:function(c,a){for(var b=this,e=/{{([^}}]+)?}}/g,d;d=e.exec(b);)var f=a?(new Function("with(this) { try { return "+d[1]+"} catch(e) { return 'error';} }")).call(c):c[d[1]],b=b.replace(d[0],f);return b},enumerable:!1});
function purgeElement(c,a){var b=c.attributes,e,d;if(b)for(e=b.length-1;0<=e;e-=1)d=b[e].name,"function"===typeof c[d]&&(c[d]=null);if(b=c.childNodes)for(b=b.length,e=0;e<b;e+=1)purgeElement(c.childNodes[e])}
"undefined"==typeof escapeHtmlEntities&&(escapeHtmlEntities=function(c){return c.replace(/[\u00A0-\u2666<>\&]/g,function(a){return"&"+(escapeHtmlEntities.entityTable[a.charCodeAt(0)]||"#"+a.charCodeAt(0))+";"})},escapeHtmlEntities.entityTable={34:"quot",38:"amp",39:"apos",60:"lt",62:"gt",160:"nbsp",161:"iexcl",162:"cent",163:"pound",164:"curren",165:"yen",166:"brvbar",167:"sect",168:"uml",169:"copy",170:"ordf",171:"laquo",172:"not",173:"shy",174:"reg",175:"macr",176:"deg",177:"plusmn",178:"sup2",
179:"sup3",180:"acute",181:"micro",182:"para",183:"middot",184:"cedil",185:"sup1",186:"ordm",187:"raquo",188:"frac14",189:"frac12",190:"frac34",191:"iquest",192:"Agrave",193:"Aacute",194:"Acirc",195:"Atilde",196:"Auml",197:"Aring",198:"AElig",199:"Ccedil",200:"Egrave",201:"Eacute",202:"Ecirc",203:"Euml",204:"Igrave",205:"Iacute",206:"Icirc",207:"Iuml",208:"ETH",209:"Ntilde",210:"Ograve",211:"Oacute",212:"Ocirc",213:"Otilde",214:"Ouml",215:"times",216:"Oslash",217:"Ugrave",218:"Uacute",219:"Ucirc",
220:"Uuml",221:"Yacute",222:"THORN",223:"szlig",224:"agrave",225:"aacute",226:"acirc",227:"atilde",228:"auml",229:"aring",230:"aelig",231:"ccedil",232:"egrave",233:"eacute",234:"ecirc",235:"euml",236:"igrave",237:"iacute",238:"icirc",239:"iuml",240:"eth",241:"ntilde",242:"ograve",243:"oacute",244:"ocirc",245:"otilde",246:"ouml",247:"divide",248:"oslash",249:"ugrave",250:"uacute",251:"ucirc",252:"uuml",253:"yacute",254:"thorn",255:"yuml",402:"fnof",913:"Alpha",914:"Beta",915:"Gamma",916:"Delta",917:"Epsilon",
918:"Zeta",919:"Eta",920:"Theta",921:"Iota",922:"Kappa",923:"Lambda",924:"Mu",925:"Nu",926:"Xi",927:"Omicron",928:"Pi",929:"Rho",931:"Sigma",932:"Tau",933:"Upsilon",934:"Phi",935:"Chi",936:"Psi",937:"Omega",945:"alpha",946:"beta",947:"gamma",948:"delta",949:"epsilon",950:"zeta",951:"eta",952:"theta",953:"iota",954:"kappa",955:"lambda",956:"mu",957:"nu",958:"xi",959:"omicron",960:"pi",961:"rho",962:"sigmaf",963:"sigma",964:"tau",965:"upsilon",966:"phi",967:"chi",968:"psi",969:"omega",977:"thetasym",
978:"upsih",982:"piv",8226:"bull",8230:"hellip",8242:"prime",8243:"Prime",8254:"oline",8260:"frasl",8472:"weierp",8465:"image",8476:"real",8482:"trade",8501:"alefsym",8592:"larr",8593:"uarr",8594:"rarr",8595:"darr",8596:"harr",8629:"crarr",8656:"lArr",8657:"uArr",8658:"rArr",8659:"dArr",8660:"hArr",8704:"forall",8706:"part",8707:"exist",8709:"empty",8711:"nabla",8712:"isin",8713:"notin",8715:"ni",8719:"prod",8721:"sum",8722:"minus",8727:"lowast",8730:"radic",8733:"prop",8734:"infin",8736:"ang",8743:"and",
8744:"or",8745:"cap",8746:"cup",8747:"int",8756:"there4",8764:"sim",8773:"cong",8776:"asymp",8800:"ne",8801:"equiv",8804:"le",8805:"ge",8834:"sub",8835:"sup",8836:"nsub",8838:"sube",8839:"supe",8853:"oplus",8855:"otimes",8869:"perp",8901:"sdot",8968:"lceil",8969:"rceil",8970:"lfloor",8971:"rfloor",9001:"lang",9002:"rang",9674:"loz",9824:"spades",9827:"clubs",9829:"hearts",9830:"diams",338:"OElig",339:"oelig",352:"Scaron",353:"scaron",376:"Yuml",710:"circ",732:"tilde",8194:"ensp",8195:"emsp",8201:"thinsp",
8204:"zwnj",8205:"zwj",8206:"lrm",8207:"rlm",8211:"ndash",8212:"mdash",8216:"lsquo",8217:"rsquo",8218:"sbquo",8220:"ldquo",8221:"rdquo",8222:"bdquo",8224:"dagger",8225:"Dagger",8240:"permil",8249:"lsaquo",8250:"rsaquo",8364:"euro"});
function beautifyCode(c,a,b){a=a||"abstract else instanceof super boolean enum int switch break export interface synchronized byte extends let this case false long throw catch final native throws char finally new transient class float null true const for package try continue function private typeof debugger goto protected var default if public void delete implements return volatile do import short while double in static with".split(" ");c=c.replace(/\b(\w+)\b/g,function(b){return-1!=a.indexOf(b)?
"<span class='rsv'>"+b+"</span>":b});c=c.replace(/\b([0-9]+)\b/g,function(a){return"<span class='num'>"+a+"</span>"});c=c.replace(/(\w+\.\w+)/g,function(a){a=a.split(".");return"<span class='obj'>"+a[0]+"</span>.<span class='prop'>"+a[1]+"</span>"});c=c.replace(/(\w+)\(/g,function(a){return"<span class='prop'>"+a.substr(0,a.length-1)+"</span>("});c=c.replace(/(\"(\\.|[^\"])*\")/g,function(a){return"<span class='str'>"+a+"</span>"});c=c.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm,function(a){return"<span class='cmnt'>"+
a.replace(/<[^>]*>/g,"")+"</span>"});b||(c="<style>.obj { color: #79B; } .prop { color: #B97; }\t.str,.num { color: #A79; } .cmnt { color: #798; } .rsv { color: #9AB; } </style>"+c);return c}
function beautifyJSON(c,a){"object"==typeof c&&(c=JSON.stringify(c));var b=["false","true","null"];c=c.replace(/(\w+)/g,function(a){return-1!=b.indexOf(a)?"<span class='rsv'>"+a+"</span>":a});c=c.replace(/([0-9]+)/g,function(a){return"<span class='num'>"+a+"</span>"});c=c.replace(/(\w+\.\w+)/g,function(a){a=a.split(".");return"<span class='obj'>"+a[0]+"</span>.<span class='prop'>"+a[1]+"</span>"});c=c.replace(/(\"(\\.|[^\"])*\")/g,function(a){return"<span class='str'>"+a+"</span>"});c=c.replace(/(\/\/[a-zA-Z0-9\?\!\(\)_ ]*)/g,
function(a){return"<span class='cmnt'>"+a+"</span>"});a||(c="<style>.obj { color: #79B; } .prop { color: #B97; }\t.str { color: #A79; } .num { color: #B97; } .cmnt { color: #798; } .rsv { color: #9AB; } </style>"+c);return c}function dataURItoBlob(c){for(var a=c.indexOf(","),b=atob(c.substr(a+1)),e=new ArrayBuffer(b.length),d=new Uint8Array(e),f=b.length,g=0;g<f;g++)d[g]=b.charCodeAt(g);c=c.substr(5,a-5);c=c.substr(0,c.length-7);return new Blob([e],{type:c})}
(function(){function c(a,b){b=b||{};a=a||"";var c=document.createElement("div");c.className="litegui searchbox";c.innerHTML="<input value='"+a+"' placeholder='"+(null!=b.placeholder?b.placeholder:"Search")+"'/>";this.input=c.querySelector("input");this.root=c;var e=this;this.input.onchange=function(a){a=a.target.value;b.callback&&b.callback.call(e,a)}}function a(a,b){function c(a){var b=parseInt(k.style.top);k.style.top=(b+0.1*a.deltaY).toFixed()+"px";a.preventDefault();return!0}this.options=b=b||
{};var e=this;b.parentMenu&&(b.parentMenu.constructor!==this.constructor?(console.error("parentMenu must be of class ContextMenu, ignoring it"),b.parentMenu=null):(this.parentMenu=b.parentMenu,this.parentMenu.lock=!0,this.parentMenu.current_submenu=this));b.event&&"MouseEvent"!==b.event.constructor.name&&"PointerEvent"!==b.event.constructor.name&&"CustomEvent"!==b.event.constructor.name&&(console.error("Event passed to ContextMenu is not of type MouseEvent or CustomEvent. Ignoring it."),b.event=null);
var k=document.createElement("div");k.className="litecontextmenu litemenubar-panel";k.style.minWidth=100;k.style.minHeight=100;k.style.pointerEvents="none";setTimeout(function(){k.style.pointerEvents="auto"},100);k.addEventListener("mouseup",function(a){a.preventDefault();return!0},!0);k.addEventListener("contextmenu",function(a){if(2!=a.button)return!1;a.preventDefault();return!1},!0);k.addEventListener("mousedown",function(a){if(2==a.button)return e.close(),a.preventDefault(),!0},!0);this.root=
k;if(b.title){var l=document.createElement("div");l.className="litemenu-title";l.innerHTML=b.title;k.appendChild(l)}var l=0,m;for(m in a){var p=a.constructor==Array?a[m]:m;null!=p&&p.constructor!==String&&(p=void 0===p.content?String(p):p.content);this.addItem(p,a[m],b);l++}k.addEventListener("mouseleave",function(a){e.lock||(k.closing_timer&&clearTimeout(k.closing_timer),k.closing_timer=setTimeout(e.close.bind(e,a),500))});k.addEventListener("mouseenter",function(a){k.closing_timer&&clearTimeout(k.closing_timer)});
k.addEventListener("wheel",c,!0);k.addEventListener("mousewheel",c,!0);m=document;b.event&&(m=b.event.target.ownerDocument);m||(m=document);m.body.appendChild(k);l=b.left||0;m=b.top||0;if(b.event)if("MouseEvent"!==b.event.constructor.name&&"PointerEvent"!==b.event.constructor.name&&"CustomEvent"!==b.event.constructor.name)console.warn("Event passed to ContextMenu is not of type MouseEvent"),b.event=null;else{l=b.event.pageX-10;m=b.event.pageY-10;b.title&&(m-=20);b.parentMenu&&(l=b.parentMenu.root.getBoundingClientRect(),
l=l.left+l.width);var p=document.body.getBoundingClientRect(),r=k.getBoundingClientRect();l>p.width-r.width-10&&(l=p.width-r.width-10);m>p.height-r.height-10&&(m=p.height-r.height-10)}k.style.left=l+"px";k.style.top=m+"px"}function b(a,b,c){c=c||{};var e=this.root=document.createElement("ul");e.id=a;e.className="litelist";this.items=[];var k=this;this.callback=c.callback;for(var l in b){a=document.createElement("li");a.className="list-item";a.data=b[l];a.dataset.value=b[l];var m="";"string"==typeof b[l]?
m=b[l]+"<span class='arrow'></span>":(m=(b[l].name||b[l].title||"")+"<span class='arrow'></span>",b[l].id&&(a.id=b[l].id));a.innerHTML=m;a.addEventListener("click",function(){for(var a=e.querySelectorAll(".list-item.selected"),b=0;b<a.length;++b)a[b].classList.remove("selected");this.classList.add("selected");LiteGUI.trigger(k.root,"wchanged",this);k.callback&&k.callback(this.data)});e.appendChild(a)}c.parent&&(c.parent.root?c.parent.root.appendChild(e):c.parent.appendChild(e))}function e(a){a=a||
{};this.root=document.createElement("div");this.root.className="litecomplexlist";this.item_code=a.item_code||"<div class='listitem'><span class='tick'><span>"+LiteGUI.special_codes.tick+"</span></span><span class='title'></span><button class='trash'>"+LiteGUI.special_codes.close+"</button></div>";a.height&&(this.root.style.height=LiteGUI.sizeToCSS(a.height));this.onItemRemoved=this.onItemToggled=this.onItemSelected=this.selected=null}LiteGUI.Button=function(a,b){b=b||{};"function"===typeof b&&(b=
{callback:b});var c=this,e=document.createElement("div");e.className="litegui button";this.root=e;var k=document.createElement("button");k.className="litebutton";this.content=k;e.appendChild(k);k.innerHTML=a;k.addEventListener("click",function(a){c.click()});this.click=function(){b.callback&&b.callback.call(c)}};c.prototype.setValue=function(a){this.input.value=a;this.input.onchange()};c.prototype.getValue=function(){return this.input.value};LiteGUI.SearchBox=c;a.prototype.addItem=function(a,b,c){function e(a){var b=
this.value;b&&b.has_submenu&&k.call(this,a)}function k(a){var b=this.value,e=!0;l.current_submenu&&l.current_submenu.close(a);if(c.callback){var d=c.callback.call(l,b,c,a);!0===d&&(e=!1)}if(b&&(b.callback&&!c.ignore_item_callbacks&&!0!==b.disabled&&(d=b.callback.call(this,b,c,a,l),!0===d&&(e=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new LiteGUI.ContextMenu(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:l,ignore_item_callbacks:b.submenu.ignore_item_callbacks,
title:b.submenu.title,autoopen:c.autoopen});e=!1}e&&!l.lock&&l.close()}var l=this;c=c||{};var m=document.createElement("div");m.className="litemenu-entry submenu";var p=!1;if(null===b)m.classList.add("separator");else{m.innerHTML=b&&b.title?b.title:a;if(m.value=b)b.disabled&&(p=!0,m.classList.add("disabled")),(b.submenu||b.has_submenu)&&m.classList.add("has_submenu");"function"==typeof b?(m.dataset.value=a,m.onclick_callback=b):m.dataset.value=b}this.root.appendChild(m);p||m.addEventListener("click",
k);c.autoopen&&m.addEventListener("mouseenter",e);return m};a.prototype.close=function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!LiteGUI.isCursorOverElement(a,this.parentMenu.root)&&LiteGUI.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};
a.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};a.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};LiteGUI.ContextMenu=a;LiteGUI.ContextualMenu=a;LiteGUI.Checkbox=function(a,b){this.value=a;var c=this.root=document.createElement("span");c.className="litecheckbox inputfield";c.dataset.value=a;var e=this.element=document.createElement("span");e.className="fixed flag checkbox "+
(a?"on":"off");c.appendChild(e);c.addEventListener("click",function(a){this.setValue("true"!=this.root.dataset.value);a.preventDefault();a.stopPropagation()}.bind(this));this.setValue=function(a){if(this.value!==a&&this.root.dataset.value!=a.toString()){(this.root.dataset.value=a)?(this.element.classList.remove("off"),this.element.classList.add("on")):(this.element.classList.remove("on"),this.element.classList.add("off"));var c=this.value;this.value=a;b&&b(a,c)}};this.getValue=function(){return this.value}};
LiteGUI.createLitebox=function(a,b){var c=document.createElement("span");c.className="listbox "+(a?"listopen":"listclosed");c.innerHTML=a?"&#9660;":"&#9658;";c.dataset.value=a?"open":"closed";c.addEventListener("click",function(a){a.target.setValue("open"==this.dataset.value?!1:!0);this.stopPropagation&&a.stopPropagation()});c.on_change_callback=b;c.setEmpty=function(a){a?this.classList.add("empty"):this.classList.remove("empty")};c.expand=function(){this.setValue(!0)};c.collapse=function(){this.setValue(!1)};
c.setValue=function(a){this.dataset.value!=(a?"open":"closed")&&(a?(this.dataset.value="open",this.innerHTML="&#9660;",this.classList.add("listopen"),this.classList.remove("listclosed")):(this.dataset.value="closed",this.innerHTML="&#9658;",this.classList.remove("listopen"),this.classList.add("listclosed")),b&&b(this.dataset.value))};c.getValue=function(){return this.dataset.value};return c};b.prototype.getSelectedItem=function(){return this.root.querySelector(".list-item.selected")};b.prototype.setSelectedItem=
function(a){for(var b=this.root.querySelectorAll(".list-item"),c=0;c<b.length;c++){var e=b[c];if(e.data==a){LiteGUI.trigger(e,"click");break}}};LiteGUI.List=b;LiteGUI.Slider=function(a,b){function c(a){var e=l.getBoundingClientRect();if(e){var d=b.min||0;m.setValue(a/e.width*((b.max||1)-d)+d)}}function e(a){var b=l.getBoundingClientRect();if(b)return c((void 0===a.x?a.pageX:a.x)-b.left),a.preventDefault(),!1}function k(a){var b=p||document;p=null;b.removeEventListener("mousemove",e);b.removeEventListener("mouseup",
k);a.preventDefault();return!1}b=b||{};var l=this.root=document.createElement("div"),m=this;this.value=a;l.className="liteslider";this.setValue=function(a,c){var e=b.min||0,d=b.max||1;a<e?a=e:a>d&&(a=d);d=(a-e)/(d-e);e=(100*d).toFixed(1)+"%";d=(100*d+2).toFixed(1)+"%";l.style.background="linear-gradient(to right, #999 "+e+", #FC0 "+d+", #333 "+d+")";if(a!=this.value&&(this.value=a,!c&&(LiteGUI.trigger(this.root,"change",a),this.onChange)))this.onChange(a)};var p=null;l.addEventListener("mousedown",
function(a){var b;a.offsetX?b=a.offsetX:a.layerX&&(b=a.layerX);c(b);p=l.ownerDocument;p.addEventListener("mousemove",e);p.addEventListener("mouseup",k);a.preventDefault();a.stopPropagation()});this.setValue(a)};LiteGUI.LineEditor=function(a,b){function c(a){return[q.width*((n.xrange[1]-n.xrange[0])*a[0]+n.xrange[0]),q.height*((n.yrange[1]-n.yrange[0])*a[1]+n.yrange[0])]}function e(a){return[(a[0]/q.width-n.xrange[0])/(n.xrange[1]-n.xrange[0]),(a[1]/q.height-n.yrange[0])/(n.yrange[1]-n.yrange[0])]}
function k(a){var b=q.getBoundingClientRect(),c=a.clientX-b.left,d=a.clientY-b.top;0>c?c=0:c>q.width&&(c=q.width);0>d?d=0:d>q.height&&(d=q.height);if(-1!=s&&p([a.clientX-b.left,a.clientY-b.top],[c,d])>0.5*q.height)n.value.splice(s,1),l(a);else{b=e([-(t[0]-c),t[1]-d]);if(-1!=s){var f=n.xrange[0],g=n.xrange[1];n.no_trespassing&&(0<s&&(f=n.value[s-1][0]),s<n.value.length-1&&(g=n.value[s+1][0]));var k=n.value[s];k[0]+=b[0];k[1]+=b[1];k[0]<f?k[0]=f:k[0]>g&&(k[0]=g);k[1]<n.yrange[0]?k[1]=n.yrange[0]:k[1]>
n.yrange[1]&&(k[1]=n.yrange[1])}r();n.redraw();t[0]=c;t[1]=d;m();a.preventDefault();a.stopPropagation()}}function l(a){s=-1;n.redraw();document.removeEventListener("mousemove",k);document.removeEventListener("mouseup",l);m();a.preventDefault();a.stopPropagation()}function m(){b.callback?b.callback.call(n,n.value):LiteGUI.trigger(n,"change")}function p(a,b){return Math.sqrt(Math.pow(b[0]-a[0],2)+Math.pow(b[1]-a[1],2))}function r(){var a=null;-1!=s&&(a=n.value[s]);n.value.sort(function(a,b){return a[0]-
b[0]});a&&(s=n.value.indexOf(a))}b=b||{};var n=document.createElement("div");n.className="curve "+(b.extraclass?b.extraclass:"");n.style.minHeight="50px";n.style.width=b.width||"100%";n.bgcolor=b.bgcolor||"#222";n.pointscolor=b.pointscolor||"#5AF";n.linecolor=b.linecolor||"#444";n.value=a||[];n.xrange=b.xrange||[0,1];n.yrange=b.yrange||[0,1];n.defaulty=null!=b.defaulty?b.defaulty:0.5;n.no_trespassing=b.no_trespassing||!1;n.show_samples=b.show_samples||0;n.options=b;n.style.minWidth="50px";n.style.minHeight=
"20px";var q=document.createElement("canvas");q.width=b.width||200;q.height=b.height||50;n.appendChild(q);n.canvas=q;n.addEventListener("mousedown",function(a){document.addEventListener("mousemove",k);document.addEventListener("mouseup",l);for(var b=q.getBoundingClientRect(),d=a.clientX-b.left,b=a.clientY-b.top,f=q.height-b,m=1E5,x=-1,w=0;w<n.value.length;w++){var u=c(n.value[w]),u=p([d,f],u);u<m&&8>u&&(m=u,x=w)}s=x;-1==s&&(f=e([d,q.height-b]),n.value.push(f),r(),s=n.value.indexOf(f));t=[d,b];n.redraw();
a.preventDefault();a.stopPropagation()});n.getValueAt=function(a){if(a<n.xrange[0]||a>n.xrange[1])return n.defaulty;for(var b=[n.xrange[0],n.defaulty],c=0,c=0;c<n.value.length;c+=1){var e=n.value[c];if(a==e[0])return e[1];if(a<e[0])return c=(a-b[0])/(e[0]-b[0]),b[1]*(1-c)+e[1]*c;b=e}e=[n.xrange[1],n.defaulty];c=(a-b[0])/(e[0]-b[0]);return b[1]*(1-c)+e[1]*c};n.resample=function(a){var b=[];a=(n.xrange[1]-n.xrange[0])/a;for(var c=n.xrange[0];c<=n.xrange[1];c+=a)b.push(n.getValueAt(c));return b};n.addValue=
function(a){for(var b=0;b<n.value;b++)if(!(n.value[b][0]<a[0])){n.value.splice(b,0,a);redraw();return}n.value.push(a);redraw()};var s=-1;n.redraw=function(){var a=q.parentNode.getBoundingClientRect();a&&q.width!=a.width&&a.width&&1E3>a.width&&(q.width=a.width);a&&q.height!=a.height&&a.height&&1E3>a.height&&(q.height=a.height);a=q.getContext("2d");a.setTransform(1,0,0,1,0,0);a.translate(0,q.height);a.scale(1,-1);a.fillStyle=n.bgcolor;a.fillRect(0,0,q.width,q.height);a.strokeStyle=n.linecolor;a.beginPath();
var b=c([n.xrange[0],n.defaulty]);a.moveTo(b[0],b[1]);for(var e in n.value)b=n.value[e],b=c(b),a.lineTo(b[0],b[1]);b=c([n.xrange[1],n.defaulty]);a.lineTo(b[0],b[1]);a.stroke();for(e=0;e<n.value.length;e+=1)b=n.value[e],b=c(b),a.fillStyle=s==e?"white":n.pointscolor,a.beginPath(),a.arc(b[0],b[1],s==e?4:2,0,2*Math.PI),a.fill();if(n.show_samples){var d=n.resample(n.show_samples);a.fillStyle="#888";for(e=0;e<d.length;e+=1)b=[(n.xrange[1]-n.xrange[0])/n.show_samples*e+n.xrange[0],d[e]],b=c(b),a.beginPath(),
a.arc(b[0],b[1],2,0,2*Math.PI),a.fill()}};var t=[0,0];n.redraw();return n};e.prototype.addTitle=function(a){a=LiteGUI.createElement("div",".listtitle",a);this.root.appendChild(a);return a};e.prototype.addHTML=function(a,b){var c=LiteGUI.createElement("div",".listtext",a);b&&c.addEventListener("mousedown",b);this.root.appendChild(c);return c};e.prototype.clear=function(){this.root.innerHTML=""};e.prototype.addItem=function(a,b,c,e){var k=LiteGUI.createListItem(this.item_code,{".title":b||a.content||
a.name});k.item=a;c&&k.classList.add("enabled");e||(k.querySelector(".trash").style.display="none");var l=this;k.addEventListener("mousedown",function(b){b.preventDefault();this.setSelected(!0);if(l.onItemSelected)l.onItemSelected(a,k)});k.querySelector(".tick").addEventListener("mousedown",function(b){b.preventDefault();k.classList.toggle("enabled");if(l.onItemToggled)l.onItemToggled(a,k,k.classList.contains("enabled"))});k.querySelector(".trash").addEventListener("mousedown",function(b){b.preventDefault();
b.stopPropagation();b.stopImmediatePropagation();if(l.onItemRemoved)l.onItemRemoved(a,k)});k.setContent=function(a,b){b?k.querySelector(".title").innerHTML=a:k.querySelector(".title").innerText=a};k.toggleEnabled=function(a){k.classList.toggle("enabled")};k.setSelected=function(a){LiteGUI.removeClass(l.root,"selected");a?this.classList.add("selected"):this.classList.remove("selected");l.selected=k.item};k.show=function(){this.style.display=""};k.hide=function(){this.style.display="none"};this.root.appendChild(k);
return k};LiteGUI.ComplexList=e})();
(function(){function c(a){a=a||{};this.root=document.createElement("div");this.root.className="liteconsole";this.root.innerHTML="<div class='log'></div><div class='foot'><input type='text'/></div>";this.log_element=this.root.querySelector(".log");this.input=this.root.querySelector("input");this.input.addEventListener("keydown",this.processKeyDown.bind(this));this._prompt=a.prompt||"]";this.onProcessCommand=this.onAutocomplete=null;this.history=[];this._history_offset=0}c.prototype.processKeyDown=
function(a){if(!this._input_blocked){if(13==a.keyCode){var b=this.input.value.trim();this.addMessage(this._prompt+b,"me",!0);this.input.value="";this.history.push(b);10<this.history.length&&this.history.shift();if(this.onProcessCommand)this.onProcessCommand(b);this._history_offset=0}else if(38==a.keyCode||40==a.keyCode){this._history_offset+=38==a.keyCode?-1:1;0<this._history_offset?this._history_offset=0:this._history_offset<-this.history.length&&(this._history_offset=-this.history.length);b=this.history.length+
this._history_offset;if(0>b)return;this.input.value=b>=this.history.length?"":this.history[b]}else if(9==a.keyCode)if(this.onAutocomplete)this.input.value=this.onAutocomplete(this.input.value);else return;else return;a.preventDefault();a.stopPropagation()}};c.prototype.addMessage=function(a,b,c){function d(a,d){g=document.createElement("pre");c?g.innerText=a:g.innerHTML=a;g.className="msg";b&&(g.className+=" "+b);f.appendChild(g);1E3<f.children.length&&f.removeChild(f.children[0])}var f=this.log_element,
g=null;if(a&&a.constructor===Array)for(var h=0;h<a.length;++h)d(a[h]);else a&&a.constructor===Object?d(JSON.stringify(a,null,""),this):d(a,this);this.log_element.scrollTop=1E6;g.update=function(a){this.innerHTML=a};return g};c.prototype.log=function(){var a=Array.prototype.slice.call(arguments).join(",");return this.addMessage(a,"msglog")};c.prototype.warn=function(){var a=Array.prototype.slice.call(arguments).join(",");return this.addMessage(a,"msgwarn")};c.prototype.error=function(){var a=Array.prototype.slice.call(arguments).join(",");
return this.addMessage(a,"msgerror")};c.prototype.clear=function(){this.log_element.innerHTML=""};LiteGUI.Console=c})();
(function(){function c(a,b){if(a&&a.constructor===String||b){var c=a;a=b||{};a.id=c;console.warn("LiteGUI.Area legacy parameter, use options as first parameter instead of id.")}a=a||{};c=document.createElement("div");c.className="litearea";a.id&&(c.id=a.id);a.className&&(c.className+=" "+a.className);this.root=c;this.root.litearea=this;var d=a.width||"100%",f=a.height||"100%";0>d&&(d="calc( 100% - "+Math.abs(d)+"px)");0>f&&(f="calc( 100% - "+Math.abs(f)+"px)");c.style.width=d;c.style.height=f;this.options=
a;var g=this;this._computed_size=[this.root.offsetWidth,this.root.offserHeight];c=document.createElement("div");a.content_id&&(c.id=a.content_id);c.className="liteareacontent";c.style.width="100%";c.style.height="100%";this.root.appendChild(c);this.content=c;this.split_direction="none";this.sections=[];a.autoresize&&LiteGUI.bind(LiteGUI,"resized",function(){g.onResize()})}c.VERTICAL="vertical";c.HORIZONTAL="horizontal";c.splitbar_size=4;c.prototype.getSection=function(a){a=a||0;return this.sections.length>
a?this.sections[a]:null};c.prototype.onResize=function(a){var b=[this.root.offsetWidth,this.root.offsetHeight];a&&this._computed_size&&b[0]==this._computed_size[0]&&b[1]==this._computed_size[1]||this.sendResizeEvent(a)};c.prototype.sendResizeEvent=function(a){if(this.sections.length)for(var b in this.sections)this.sections[b].onResize(a);else for(a=0;a<this.root.childNodes.length;a++)if(b=this.root.childNodes[a],b.litearea)b.litearea.onResize();else LiteGUI.trigger(b,"resize");if(this.onresize)this.onresize()};
c.prototype.getWidth=function(){return this.root.offsetWidth};c.prototype.getHeight=function(){return this.root.offsetHeight};c.prototype.isVisible=function(){return"none"!=this.root.style.display};c.prototype.adjustHeight=function(){if(this.root.parentNode){var a=this.root.getClientRects()[0].top;this.root.style.height="calc( 100% - "+a+"px )"}else console.error("Cannot adjust height of LiteGUI.Area without parent")};c.prototype.split=function(a,b,e){function d(a){var b=r.root.ownerDocument;b.addEventListener("mousemove",
f);b.addEventListener("mouseup",g);n[0]=a.pageX;n[1]=a.pageY;a.stopPropagation();a.preventDefault()}function f(b){"horizontal"==a?n[0]!=b.pageX&&r.moveSplit(n[0]-b.pageX):"vertical"==a&&n[1]!=b.pageY&&r.moveSplit(b.pageY-n[1]);n[0]=b.pageX;n[1]=b.pageY;b.stopPropagation();b.preventDefault();if(r.options.immediateResize||r.options.inmediateResize)r.onResize()}function g(a){a=r.root.ownerDocument;a.removeEventListener("mousemove",f);a.removeEventListener("mouseup",g);r.onResize()}if(!a||a.constructor!==
String)throw"First parameter must be a string: 'vertical' or 'horizontal'";b||(b=["50%",null]);if("vertical"!=a&&"horizontal"!=a)throw"First parameter must be a string: 'vertical' or 'horizontal'";if(this.sections.length)throw"cannot split twice";var h=new LiteGUI.Area({content_id:this.content.id});h.root.style.display="inline-block";var k=new LiteGUI.Area;k.root.style.display="inline-block";var l="",m=null,p=null;e&&(l=" - "+(c.splitbar_size+2)+"px",m=document.createElement("div"),m.className="litesplitbar "+
a,"vertical"==a?m.style.height=c.splitbar_size+"px":m.style.width=c.splitbar_size+"px",this.splitbar=m,m.addEventListener("mousedown",d));b=b||["50%",null];"vertical"==a?(h.root.style.width="100%",k.root.style.width="100%",null==b[0]?(p=b[1],"number"==typeof p&&(p=b[1]+"px"),h.root.style.height="-moz-calc( 100% - "+p+l+" )",h.root.style.height="-webkit-calc( 100% - "+p+l+" )",h.root.style.height="calc( 100% - "+p+l+" )",k.root.style.height=p,k.size=p,p=h):null==b[1]?(p=b[0],"number"==typeof p&&(p=
b[0]+"px"),h.root.style.height=p,h.size=p,k.root.style.height="-moz-calc( 100% - "+p+l+" )",k.root.style.height="-webkit-calc( 100% - "+p+l+" )",k.root.style.height="calc( 100% - "+p+l+" )",p=k):(l=b[0],"number"==typeof l&&(l=b[0]+"px"),e=b[1],"number"==typeof e&&(e=b[1]+"px"),h.root.style.height=l,h.size=l,k.root.style.height=e,k.size=e)):(h.root.style.height="100%",k.root.style.height="100%",null==b[0]?(p=b[1],"number"==typeof p&&(p=b[1]+"px"),h.root.style.width="-moz-calc( 100% - "+p+l+" )",h.root.style.width=
"-webkit-calc( 100% - "+p+l+" )",h.root.style.width="calc( 100% - "+p+l+" )",k.root.style.width=p,k.size=b[1],p=h):null==b[1]?(p=b[0],"number"==typeof p&&(p=b[0]+"px"),h.root.style.width=p,h.size=p,k.root.style.width="-moz-calc( 100% - "+p+l+" )",k.root.style.width="-webkit-calc( 100% - "+p+l+" )",k.root.style.width="calc( 100% - "+p+l+" )",p=k):(l=b[0],"number"==typeof l&&(l=b[0]+"px"),e=b[1],"number"==typeof e&&(e=b[1]+"px"),h.root.style.width=l,h.size=l,k.root.style.width=e,k.size=e));h.root.removeChild(h.content);
h.root.appendChild(this.content);h.content=this.content;this.root.appendChild(h.root);m&&this.root.appendChild(m);this.root.appendChild(k.root);this.sections=[h,k];this.dynamic_section=p;this.direction=a;var r=this,n=[0,0]};c.prototype.hide=function(){this.root.style.display="none"};c.prototype.show=function(){this.root.style.display="block"};c.prototype.showSection=function(a){var b=this.sections[a],c=0;if(!b||"none"==b.root.style.display){c="horizontal"==this.direction?b.root.style.width:b.root.style.height;
-1!=c.indexOf("calc")&&(c="50%");for(var d in this.sections)b=this.sections[d],d==a?b.root.style.display="inline-block":"horizontal"==this.direction?b.root.style.width="calc( 100% - "+c+" - 5px)":b.root.style.height="calc( 100% - "+c+" - 5px)";this.splitbar&&(this.splitbar.style.display="inline-block");this.sendResizeEvent()}};c.prototype.hideSection=function(a){for(var b in this.sections){var c=this.sections[b];b==a?c.root.style.display="none":"horizontal"==this.direction?c.root.style.width="100%":
c.root.style.height="100%"}this.splitbar&&(this.splitbar.style.display="none");this.sendResizeEvent()};c.prototype.moveSplit=function(a){if(this.sections){var b=this.sections[0],e=this.sections[1],d=" - "+c.splitbar_size+"px",f=this.options.minSplitSize||10;"horizontal"==this.direction?this.dynamic_section==b?(a=e.root.offsetWidth+a,a<f&&(a=f),b.root.style.width="-moz-calc( 100% - "+a+"px "+d+" )",b.root.style.width="-webkit-calc( 100% - "+a+"px "+d+" )",b.root.style.width="calc( 100% - "+a+"px "+
d+" )",e.root.style.width=a+"px"):(a=b.root.offsetWidth-a,a<f&&(a=f),e.root.style.width="-moz-calc( 100% - "+a+"px "+d+" )",e.root.style.width="-webkit-calc( 100% - "+a+"px "+d+" )",e.root.style.width="calc( 100% - "+a+"px "+d+" )",b.root.style.width=a+"px"):"vertical"==this.direction&&(this.dynamic_section==b?(a=e.root.offsetHeight-a,a<f&&(a=f),b.root.style.height="-moz-calc( 100% - "+a+"px "+d+" )",b.root.style.height="-webkit-calc( 100% - "+a+"px "+d+" )",b.root.style.height="calc( 100% - "+a+
"px "+d+" )",e.root.style.height=a+"px"):(a=b.root.offsetHeight+a,a<f&&(a=f),e.root.style.height="-moz-calc( 100% - "+a+"px "+d+" )",e.root.style.height="-webkit-calc( 100% - "+a+"px "+d+" )",e.root.style.height="calc( 100% - "+a+"px "+d+" )",b.root.style.height=a+"px"));LiteGUI.trigger(this.root,"split_moved");b=this.root.querySelectorAll(".litearea");for(e=0;e<b.length;++e)LiteGUI.trigger(b[e],"split_moved")}};c.prototype.addEventListener=function(a,b,c,d){return this.root.addEventListener(a,b,
c,d)};c.prototype.setAreaSize=function(a,b){var e=this.sections[1],d=" - "+c.splitbar_size+"px";e.root.style.width="-moz-calc( 100% - "+b+d+" )";e.root.style.width="-webkit-calc( 100% - "+b+d+" )";e.root.style.width="calc( 100% - "+b+d+" )"};c.prototype.merge=function(a){if(0==this.sections.length)throw"not splitted";a=this.sections[a||0];this.root.appendChild(a.content);this.content=a.content;this.root.removeChild(this.sections[0].root);this.root.removeChild(this.sections[1].root);this.sections=
[];this._computed_size=null;this.onResize()};c.prototype.add=function(a){if("string"==typeof a){var b=document.createElement("div");b.innerHTML=a;a=b}this.content.appendChild(a.root||a)};c.prototype.query=function(a){return this.root.querySelector(a)};LiteGUI.Area=c;LiteGUI.Split=function(a,b,c){b=b||{};if(a&&a.constructor===String){var d=a;a=b;b=c||{};b.id=d;console.warn("LiteGUI.Split legacy parameter, use sections as first parameter instead of id.")}this.root=c=document.createElement("div");b.id&&
(c.id=d);c.className="litesplit "+(b.vertical?"vsplit":"hsplit");this.sections=[];for(var f in a)d=document.createElement("div"),d.className="split-section split"+f,"number"==typeof a[f]?b.vertical?d.style.height=a[f].toFixed(1)+"%":d.style.width=a[f].toFixed(1)+"%":"string"==typeof a[f]?b.vertical?d.style.height=a[f]:d.style.width=a[f]:(a[f].id&&(d.id=a[f].id),b.vertical?d.style.height="Number"==typeof a[f].height?a[f].height.toFixed(1)+"%":a[f].height:d.style.width="Number"==typeof a[f].width?a[f].width.toFixed(1)+
"%":a[f].width),d.add=function(a){this.appendChild(a.root||a)},this.sections.push(d),c.appendChild(d);b.parent&&(b.parent.root?b.parent.root.appendChild(c):b.parent.appendChild(c));this.getSection=function(a){return this.sections[a]}}})();
(function(){function c(a,b){b=b||{};this.menu=[];this.panels=[];this.root=document.createElement("div");this.root.id=a;this.root.className="litemenubar";this.content=document.createElement("ul");this.root.appendChild(this.content);this.is_open=!1;this.auto_open=b.auto_open||!1;this.sort_entries=b.sort_entries||!1}c.closing_time=500;c.prototype.clear=function(){this.content.innerHTML="";this.menu=[];this.panels=[]};c.prototype.attachToPanel=function(a){a.content.insertBefore(this.root,a.content.firstChild)};
c.prototype.add=function(a,b){b=b||{};"function"==typeof b&&(b={callback:b});for(var c=this.menu.length,d=a.split("/"),f=0,g=0,h=this.menu,k=null;h;){if(5<f)throw"Error: Menubar too deep";if(h.length==g){k=g={parent:k,children:[]};f==d.length-1&&(g.data=b);g.disable=function(){this.data&&(this.data.disabled=!0)};g.enable=function(){this.data&&delete this.data.disabled};g.name=d[f];h.push(g);f++;if(f==d.length)break;g.children=[];h=g.children;g=0}else{if(h[g]&&d[f]==h[g].name)if(f<d.length-1){k=h[g];
h=h[g].children;g=0;f++;continue}else{console.warn("Warning: Adding menu that already exists: "+a);break}g++}}c!=this.menu.length&&this.updateMenu()};c.prototype.remove=function(a){if(a=this.findMenu(a)){if(!a.parent||!a.parent.children)return console.warn("menu without parent?");var b=a.parent.children.indexOf(a);-1!=b&&a.parent.children.splice(b,1)}};c.prototype.separator=function(a,b){var c=this.findMenu(a);c&&c.children.push({separator:!0,order:b||10})};c.prototype.findMenu=function(a){a=a.split("/");
for(var b=0,c=0,d=this.menu;d;){if(b==a.length)return d;if(d.length<=c)break;if("*"==a[b])return d[c].children;if(a[b]==d[c].name){if(b==a.length-1)return d[c];d=d[c].children;c=0;b++}else c++}return null};c.prototype.updateMenu=function(){var a=this;this.content.innerHTML="";for(var b in this.menu){var c=document.createElement("li");c.innerHTML="<span class='icon'></span><span class='name'>"+this.menu[b].name+"</span>";this.content.appendChild(c);c.data=this.menu[b];this.menu[b].element=c;c.addEventListener("click",
function(b){var c=this.data;c.data&&c.data.callback&&"function"==typeof c.data.callback&&c.data.callback(c.data);a.is_open?(a.is_open=!1,a.hidePanels()):(a.is_open=!0,a.showMenu(c,b,this))});c.addEventListener("mouseover",function(b){a.hidePanels();(a.is_open||a.auto_open)&&a.showMenu(this.data,b,this)})}};c.prototype.hidePanels=function(){if(this.panels.length){for(var a in this.panels)LiteGUI.remove(this.panels[a]);this.panels=[]}};c.prototype.showMenu=function(a,b,c,d){d||this.hidePanels();if(a.children&&
a.children.length){var f=this;f.closing_by_leave&&clearInterval(f.closing_by_leave);var g=document.createElement("div");g.className="litemenubar-panel";var h=[],k;for(k in a.children)h.push(a.children[k]);this.sort_entries&&h.sort(function(a,b){var c=10,e=10;a&&a.data&&null!=a.data.order&&(c=a.data.order);a&&a.separator&&null!=a.order&&(c=a.order);b&&b.data&&null!=b.data.order&&(e=b.data.order);b&&b.separator&&null!=b.order&&(e=b.order);return c-e});for(k in h){a=document.createElement("p");var l=
h[k];a.className="litemenu-entry "+(a.children?" submenu":"");var m=l.children&&l.children.length;m&&a.classList.add("has_submenu");l&&l.name?a.innerHTML="<span class='icon'></span><span class='name'>"+l.name+(m?"<span class='more'>+</span>":"")+"</span>":a.classList.add("separator");a.data=l;if(a.data.data){l=a.data.data;if("checkbox"==l.type&&l.instance&&l.property&&!0==l.instance[l.property]||!0==l.checkbox||l.instance&&l.property&&l.hasOwnProperty("value")&&l.instance[l.property]==l.value||"function"==
typeof l.isChecked&&l.isChecked.call(l.instance,l))a.className+=" checked";l.disabled&&(a.className+=" disabled")}a.addEventListener("click",function(){var a=this.data;if(a.data){if(a.data.disabled)return;a.data.instance&&a.data.property&&("checkbox"==a.data.type?(a.data.instance[a.data.property]=!a.data.instance[a.data.property],a.data.instance[a.data.property]?this.classList.add("checked"):this.classList.remove("checked")):a.data.hasOwnProperty("value")&&(a.data.instance[a.data.property]=a.data.value));
null!=a.data.checkbox&&(a.data.checkbox=!a.data.checkbox,a.data.checkbox?this.classList.add("checked"):this.classList.remove("checked"));a.data.callback&&"function"==typeof a.data.callback&&a.data.callback(a.data)}a.children&&a.children.length?f.showMenu(a,b,this,!0):(f.is_open=!1,f.hidePanels())});a.addEventListener("mouseenter",function(a){});g.appendChild(a)}g.addEventListener("mouseleave",function(a){f.closing_by_leave&&clearInterval(f.closing_by_leave);f.closing_by_leave=setTimeout(function(){f.is_open=
!1;f.hidePanels()},LiteGUI.Menubar.closing_time)});g.addEventListener("mouseenter",function(a){f.closing_by_leave&&clearInterval(f.closing_by_leave);f.closing_by_leave=null});c=c.getBoundingClientRect();g.style.left=c.left+(d?200:0)+"px";g.style.top=c.top+c.height+(d?-20:10)+"px";this.panels.push(g);document.body.appendChild(g)}};LiteGUI.Menubar=c})();
(function(){function c(a,b){function c(a){a.deltaY&&(g.scrollLeft+=a.deltaY)}if(b||a&&a.constructor===String){var d=a;a=b||{};a.id=d;console.warn("LiteGUI.Tabs legacy parameter, use options as first parameter instead of id.")}this.options=a=a||{};var d=this.mode=a.mode||"horizontal",f=document.createElement("DIV");a.id&&(f.id=a.id);f.data=this;f.className="litetabs "+d;this.root=f;this.root.tabs=this;this.current_tab=null;"horizontal"==d?a.size&&(this.root.style.height="full"==a.size?"100%":a.size):
"vertical"==d&&a.size&&(this.root.style.width="full"==a.size?"100%":a.size);a.width&&(this.root.style.width=a.width.constructor===Number?a.width.toFixed(0)+"px":a.width);a.height&&(this.root.style.height=a.height.constructor===Number?a.height.toFixed(0)+"px":a.height);var g=document.createElement("UL");g.className="wtabcontainer";"vertical"==d?g.style.width=LiteGUI.Tabs.tabs_width+"px":g.style.height=LiteGUI.Tabs.tabs_height+"px";g.addEventListener("wheel",c);g.addEventListener("mousewheel",c);this.list=
g;this.root.appendChild(this.list);this.tabs_root=g;this.tabs={};this.tabs_by_index=[];this.selected=null;this.onchange=a.callback;a.parent&&this.appendTo(a.parent)}c.tabs_width=64;c.tabs_height=26;c.prototype.show=function(){this.root.style.display="block"};c.prototype.hide=function(){this.root.style.display="none"};c.prototype.getCurrentTab=function(){return this.current_tab?this.tabs[this.current_tab[0]]:null};c.prototype.getCurrentTabId=function(){return this.current_tab[0]};c.prototype.getPreviousTab=
function(){return this.previous_tab?this.tabs[this.previous_tab[0]]:null};c.prototype.appendTo=function(a,b){b?a.prepend(this.root):a.appendChild(this.root)};c.prototype.getTab=function(a){return this.tabs[a]};c.prototype.getTabByIndex=function(a){return this.tabs_by_index[a]};c.prototype.getNumOfTabs=function(){var a=0,b;for(b in this.tabs)a++;return a};c.prototype.getTabContent=function(a){if(a=this.tabs[a])return a.content};c.prototype.getTabIndex=function(a){a=this.tabs[a];if(!a)return-1;for(var b=
0;b<this.list.childNodes.length;b++)if(this.list.childNodes[b]==a.tab)return b;return-1};c.prototype.addTab=function(a,b,e){b=b||{};"function"==typeof b&&(b={callback:b});var d=this;if(void 0===a||null===a)a="rand_"+(1E6*Math.random()|0);e=document.createElement("LI");var f=a.replace(/ /gi,"_");e.className="wtab wtab-"+f+" ";e.dataset.id=a;e.innerHTML="<span class='tabtitle'>"+(b.title||a)+"</span>";b.button&&(e.className+="button ");b.tab_className&&(e.className+=b.tab_className);b.bigicon&&(e.innerHTML=
"<img class='tabbigicon' src='"+b.bigicon+"'/>"+e.innerHTML);b.closable&&(e.innerHTML+="<span class='tabclose'>"+LiteGUI.special_codes.close+"</span>",e.querySelector("span.tabclose").addEventListener("click",function(b){d.removeTab(a);b.preventDefault();b.stopPropagation()},!0));if(void 0!==b.index){var g=this.list.childNodes[b.index];g?this.list.insertBefore(e,g):this.list.appendChild(e)}else this.plus_tab?this.list.insertBefore(e,this.plus_tab):this.list.appendChild(e);b.tab_width&&(e.style.width=
b.tab_width.constructor===Number?b.tab_width.toFixed(0)+"px":b.tab_width,e.style.minWidth="0");this.options.autoswitch&&(e.classList.add("autoswitch"),e.addEventListener("dragenter",function(a){d._timeout_mouseover&&clearTimeout(d._timeout_mouseover);d._timeout_mouseover=setTimeout(function(){LiteGUI.trigger(this,"click");d._timeout_mouseover=null}.bind(this),500)}),e.addEventListener("dragleave",function(a){d._timeout_mouseover&&(clearTimeout(d._timeout_mouseover),d._timeout_mouseover=null)}));g=
document.createElement("div");b.id&&(g.id=b.id);g.className="wtabcontent wtabcontent-"+f+" "+(b.className||"");g.dataset.id=a;g.style.display="none";"horizontal"==this.mode?b.size&&(g.style.overflow="auto","full"==b.size?(g.style.width="100%",g.style.height="calc( 100% - "+LiteGUI.Tabs.tabs_height+"px )",g.style.height="-moz-calc( 100% - "+LiteGUI.Tabs.tabs_height+"px )",g.style.height="-webkit-calc( 100% - "+LiteGUI.Tabs.tabs_height+"px )"):g.style.height=b.size):"vertical"==this.mode&&b.size&&(g.style.overflow=
"auto","full"==b.size?(g.style.height="100%",g.style.width="calc( 100% - "+LiteGUI.Tabs.tabs_width+"px )",g.style.width="-moz-calc( 100% - "+LiteGUI.Tabs.tabs_width+"px )",g.style.width="-webkit-calc( 100% - "+LiteGUI.Tabs.tabs_width+"px )"):g.style.width=b.size);void 0!==b.width&&(g.style.width="string"===typeof b.width?b.width:b.width+"px");void 0!==b.height&&(g.style.height="string"===typeof b.height?b.height:b.height+"px");b.content&&("string"==typeof b.content?g.innerHTML=b.content:g.appendChild(b.content));
this.root.appendChild(g);b.button?e.addEventListener("click",function(a){var c=this.dataset.id;b.callback&&b.callback(c,a)}):e.addEventListener("click",c.prototype.onTabClicked);e.options=b;e.tabs=this;var f=e.querySelector("span.tabtitle"),h={id:a,tab:e,content:g,title:f,add:function(a){this.content.appendChild(a.root||a)},setTitle:function(a){this.title.innerHTML=a},click:function(){LiteGUI.trigger(this.tab,"click")},destroy:function(){d.removeTab(this.id)}};b.onclose&&(h.onclose=b.onclose);this.tabs[a]=
h;this.recomputeTabsByIndex();e.addEventListener("contextmenu",function(a){if(2!=a.button)return!1;a.preventDefault();b.callback_context&&b.callback_context.call(h);return!1}.bind(this));!0!=b.selected&&null!=this.selected||this.selectTab(a,b.skip_callbacks);return h};c.prototype.addPlusTab=function(a){this.plus_tab&&console.warn("There is already a plus tab created in this tab widget");this.plus_tab=this.addTab("plus_tab",{title:"+",tab_width:20,button:!0,callback:a,skip_callbacks:!0})};c.prototype.addButtonTab=
function(a,b,c){return this.addTab(a,{title:b,tab_width:20,button:!0,callback:c,skip_callbacks:!0})};c.prototype.onTabClicked=function(a){if(!this.classList.contains("selected")&&this.parentNode){var b=this.options,c=this.parentNode.parentNode.tabs;if(!c)throw"tabs not found";if(!b.callback_canopen||!1!=b.callback_canopen()){c.current_tab&&c.current_tab[0]!=d&&c.current_tab[2]&&c.current_tab[2].callback_leave&&c.current_tab[2].callback_leave(c.current_tab[0],c.current_tab[1],c.current_tab[2]);var d=
this.dataset.id,f=null,g;for(g in c.tabs){var h=c.tabs[g];g==d?(h.selected=!0,h.content.style.display="",f=h.content):(delete h.selected,h.content.style.display="none")}h=c.list.querySelectorAll("li.wtab");for(g=0;g<h.length;++g)h[g].classList.remove("selected");this.classList.add("selected");c.previous_tab=c.current_tab;c.current_tab=[d,f,b];if(a&&(b.callback&&b.callback(d,f,a),LiteGUI.trigger(c,"wchange",[d,f]),c.onchange))c.onchange(d,f);c.selected=d}}};c.prototype.selectTab=function(a,b){if(a){a.constructor!=
String&&(a=a.id);for(var c=this.list.querySelectorAll("li.wtab"),d=0;d<c.length;d++)if(a==c[d].dataset.id){this.onTabClicked.call(c[d],!b);break}}};c.prototype.setTabVisibility=function(a,b){var c=this.tabs[a];c&&(c.tab.style.display=b?"none":null,c.content.style.display=b?"none":null)};c.prototype.recomputeTabsByIndex=function(){this.tabs_by_index=[];for(var a in this.tabs){for(var b=this.tabs[a],c=0,d=b.tab;null!=(d=d.previousSibling);)c++;this.tabs_by_index[c]=b}};c.prototype.removeTab=function(a){var b=
this.tabs[a];if(b){if(b.onclose)b.onclose(b);b.tab.parentNode&&b.tab.parentNode.removeChild(b.tab);b.content.parentNode&&b.content.parentNode.removeChild(b.content);delete this.tabs[a];this.recomputeTabsByIndex()}else console.warn("tab not found: "+a)};c.prototype.removeAllTabs=function(a){var b=[],c;for(c in this.tabs)b.push(this.tabs[c]);for(c in b){var d=b[c];d==this.plus_tab&&a||(d.tab.parentNode&&d.tab.parentNode.removeChild(d.tab),d.content.parentNode&&d.content.parentNode.removeChild(d.content),
delete this.tabs[d.id])}this.recomputeTabsByIndex()};c.prototype.clear=function(){this.removeAllTabs()};c.prototype.hideTab=function(a){this.setTabVisibility(a,!1)};c.prototype.showTab=function(a){this.setTabVisibility(a,!0)};c.prototype.transferTab=function(a,b,c){var d=this.tabs[a];if(d){b.tabs[a]=d;void 0!==c?b.list.insertBefore(d.tab,b.list.childNodes[c]):b.list.appendChild(d.tab);b.root.appendChild(d.content);delete this.tabs[a];c=null;for(var f in this.tabs){c=f;break}c&&this.selectTab(c);d.tab.classList.remove("selected");
b.selectTab(a)}};c.prototype.detachTab=function(a,b,c){if(this.tabs[a]){var d=this.getTabIndex(a),f=window.open("","","width=800, height=600, location=no, status=no, menubar=no, titlebar=no, fullscreen=yes");f.document.write("<head><title>"+a+"</title>");for(var g=document.querySelectorAll("link[rel='stylesheet'],style"),h=0;h<g.length;h++)f.document.write(g[h].outerHTML);f.document.write("</head><body></body>");f.document.close();var k=this,l=new LiteGUI.Tabs(null,this.options);f.tabs=l;f.onbeforeunload=
function(){l.transferTab(a,k,d);c&&c()};l.list.style.height="20px";f.document.body.appendChild(l.root);k.transferTab(a,l);l.tabs[a].tab.classList.add("selected");this.recomputeTabsByIndex();b&&b();return f}};LiteGUI.Tabs=c})();
(function(){function c(a,b){function c(a){var e=[a.screenX-r.data[0],r.data[1]-a.screenY];void 0!==a.movementX&&(e=[a.movementX,-a.movementY]);r.data=[a.screenX,a.screenY];g(e[b.horizontal?0:1],a);a.stopPropagation();a.preventDefault();return!1}function d(a){document.activeElement===this&&(g(0<(void 0!==a.wheelDelta?a.wheelDelta:a.deltaY?-a.deltaY/3:0)?1:-1,a),a.stopPropagation(),a.preventDefault())}function f(a){LiteGUI.trigger(k,"stop_dragging");var b=n||document;n=null;b.removeEventListener("mousemove",
c);b.removeEventListener("mouseup",f);b.exitPointerLock&&b.exitPointerLock();LiteGUI.trigger(r,"blur");a.stopPropagation();a.preventDefault();return!1}function g(a,c){b.linear||(a=0<a?Math.pow(a,1.2):-1*Math.pow(Math.abs(a),1.2));var e=b.step?b.step:1;c&&c.shiftKey?e*=10:c&&c.ctrlKey&&(e*=0.1);e=parseFloat(p.value)+a*e;null!=b.max&&e>b.max&&(e=b.max);null!=b.min&&e<b.min&&(e=b.min);p.value=e.toFixed(h);b.units&&(p.value+=b.units);LiteGUI.trigger(p,"change")}null===a||void 0===a?a=0:a.constructor===
String?a=parseFloat(a):a.constructor!==Number&&(a=0);this.value=a;var h=void 0!=b.precision?b.precision:3;this.options=b||{};var k=document.createElement("div");k.className="dragger "+(b.extraclass?b.extraclass:"");this.root=k;var l=document.createElement("span");l.className="inputfield "+(b.extraclass?b.extraclass:"")+(b.full?" full":"");b.disabled&&(l.className+=" disabled");k.appendChild(l);var m=b.dragger_class||"full",p=document.createElement("input");p.className="text number "+(m?m:"");p.value=
a.toFixed(h)+(b.units?b.units:"");p.tabIndex=b.tab_index;this.input=p;k.input=p;b.disabled&&(p.disabled=!0);b.tab_index&&(p.tabIndex=b.tab_index);l.appendChild(p);p.addEventListener("keydown",function(a){if(38==a.keyCode)g(1,a);else if(40==a.keyCode)g(-1,a);else return;a.stopPropagation();a.preventDefault();return!0});var r=document.createElement("div");r.className="drag_widget";b.disabled&&(r.className+=" disabled");l.appendChild(r);k.dragger=r;r.addEventListener("mousedown",function(a){n=p.ownerDocument;
n.removeEventListener("mousemove",c);n.removeEventListener("mouseup",f);b.disabled||(k.requestPointerLock&&k.requestPointerLock(),n.addEventListener("mousemove",c),n.addEventListener("mouseup",f),r.data=[a.screenX,a.screenY],LiteGUI.trigger(k,"start_dragging"));a.stopPropagation();a.preventDefault()});p.addEventListener("wheel",d,!1);p.addEventListener("mousewheel",d,!1);var n=null}c.prototype.setRange=function(a,b){this.options.min=a;this.options.max=b};c.prototype.setValue=function(a,b){this.value=
a=parseFloat(a);this.options.precision&&(a=a.toFixed(this.options.precision));this.options.units&&(a+=this.options.units);this.input.value=a;b||LiteGUI.trigger(this.input,"change")};c.prototype.getValue=function(){return this.value};LiteGUI.Dragger=c})();
(function(){function c(a,b,c){if(c||a&&a.constructor===String){var d=a;a=b;b=c||{};b.id=d;console.warn("LiteGUI.Tree legacy parameter, use data as first parameter instead of id.")}b=b||{};this.root=c=document.createElement("div");b.id&&(c.id=b.id);c.className="litetree";this.tree=a;var f=this;this.options=b=b||{allow_rename:!1,allow_drag:!0,allow_multiselection:!1};this.indent_offset=b.indent_offset||0;b.height&&(this.root.style.height="string"==typeof b.height?b.height:Math.round(b.height)+"px");
this.collapsed_depth=3;null!=b.collapsed_depth&&(this.collapsed_depth=b.collapsed_depth);c.addEventListener("click",function(a){if(a.srcElement==f.root&&f.onBackgroundClicked)f.onBackgroundClicked(a,f)});c.addEventListener("contextmenu",function(a){if(2!=a.button)return!1;if(f.onContextMenu)f.onContextMenu(a);a.preventDefault();return!1});a=this.createAndInsert(a,b,null);if(!a)throw"Error in LiteGUI.Tree, createAndInsert returned null";a.className+=" root_item";this.root_item=a}c.INDENT=20;c.prototype.updateTree=
function(a){this.root.innerHTML="";(a=this.createAndInsert(a,this.options,null))?(a.className+=" root_item",this.root_item=a):this.root_item=null};c.prototype.insertItem=function(a,b,c,d){if(!b){var f=this.root.childNodes[0];f&&(b=f.dataset.item_id)}a=this.createAndInsert(a,d,b,c);b&&this._updateListBox(this._findElement(b));return a};c.prototype.createAndInsert=function(a,b,c,d){var f=-1;c?f=this._findElementIndex(c):void 0===c&&(f=0);var g=null,h=0;-1!=f&&(g=this.root.childNodes[f],h=parseInt(g.dataset.level)+
1);var k=this.createTreeItem(a,b,h);if(k){k.parent_id=c;this.getItem(k.dataset.item_id)&&console.warn("There another item with the same ID in this tree");-1==f?this.root.appendChild(k):this._insertInside(k,f,d);g&&!this._isNodeChildrenVisible(c)&&k.classList.add("hidden");if(a.children)for(c=0;c<a.children.length;++c)this.createAndInsert(a.children[c],b,a.id);this._updateListBox(k,b,h);b&&b.selected&&this.markAsSelected(k,!0);return k}};c.prototype._insertInside=function(a,b,e,d){var f=this.root.childNodes[b];
if(!f)throw"No parent node found, index: "+b+", nodes: "+this.root.childNodes.length;f=parseInt(f.dataset.level);d=void 0!==d?d:f+1;if(f=a.querySelector(".indentblock"))f.style.paddingLeft=(d+this.indent_offset)*c.INDENT+"px";a.dataset.level=d;for(b+=1;b<this.root.childNodes.length;++b)if(f=this.root.childNodes[b],f.classList&&f.classList.contains("ltreeitem")){var g=parseInt(f.dataset.level);if(g==d&&e)e--;else if(g<d||0===e&&g===d){this.root.insertBefore(a,f);return}}this.root.appendChild(a)};c.prototype._isNodeChildrenVisible=
function(a){a=this.getItem(a);return!a||a.classList.contains("hidden")?!1:(a=a.querySelector(".listbox"))?"closed"==a.getValue()?!1:!0:!0};c.prototype._findElement=function(a){if(!a||a.constructor!==String)throw"findElement param must be string with item id";for(var b=0;b<this.root.childNodes.length;++b){var c=this.root.childNodes[b];if(c.classList&&c.classList.contains("ltreeitem")&&c.classList.contains("ltreeitem-"+a))return c}return null};c.prototype._findElementIndex=function(a){for(var b=0;b<
this.root.childNodes.length;++b){var c=this.root.childNodes[b];if(c.classList&&c.classList.contains("ltreeitem"))if("string"===typeof a){if(c.dataset.item_id===a)return b}else if(c===a)return b}return-1};c.prototype._findElementLastChildIndex=function(a){if(-1==a)return-1;var b=parseInt(this.root.childNodes[a].dataset.level);for(a+=1;a<this.root.childNodes.length;++a){var c=this.root.childNodes[a];if(c.classList&&c.classList.contains("ltreeitem")&&parseInt(c.dataset.level)==b)return a}return-1};c.prototype._findChildElements=
function(a,b){var c=this._findElementIndex(a);if(-1!=c){for(var d=parseInt(this.root.childNodes[c].dataset.level),f=[],c=c+1;c<this.root.childNodes.length;++c){var g=this.root.childNodes[c];if(g.classList&&g.classList.contains("ltreeitem")){var h=parseInt(g.dataset.level);if(!(b&&h>d+1)){if(h<=d)break;f.push(g)}}}return f}};c.prototype.createTreeItem=function(a,b,c){function d(b){b.preventDefault();b.stopPropagation();if(!this.title_element._editing){if(b.ctrlKey&&h.options.allow_multiselection){if(h.isNodeSelected(this)){this.classList.remove("selected");
LiteGUI.trigger(h,"item_remove_from_selection",{item:this,data:this.data});LiteGUI.trigger(h.root,"item_remove_from_selection",{item:this,data:this.data});return}h.markAsSelected(this,!0);LiteGUI.trigger(h,"item_add_to_selection",{item:this,data:this.data});LiteGUI.trigger(h.root,"item_add_to_selection",{item:this,data:this.data});var c=!1;a.callback&&(c=a.callback.call(h,this));if(!c&&h.onItemAddToSelection)h.onItemAddToSelection(this.data,this)}if(b.shiftKey&&h.options.allow_multiselection){if((c=
h.getSelectedItem())&&c!==this){b=Array.prototype.slice.call(c.parentNode.children);var c=b.indexOf(c),e=b.indexOf(this);b=e>c?b.slice(c,e):b.slice(e,c);for(c=0;c<b.length;++c)e=b[c],h.markAsSelected(e,!0),LiteGUI.trigger(h,"item_add_to_selection",{item:e,data:e.data}),LiteGUI.trigger(h.root,"item_add_to_selection",{item:e,data:e.data})}}else{h.markAsSelected(this);h._skip_scroll=!0;LiteGUI.trigger(h,"item_selected",{item:this,data:this.data});LiteGUI.trigger(h.root,"item_selected",{item:this,data:this.data});
c=!1;a.callback&&(c=a.callback.call(h,this));if(!c&&h.onItemSelected)h.onItemSelected(this.data,this);h._skip_scroll=!1}}}function f(a){var b=this,c=b.title_element.querySelector(".incontent");LiteGUI.trigger(h,"item_dblclicked",b);LiteGUI.trigger(h.root,"item_dblclicked",b);if(!c._editing&&h.options.allow_rename){c._editing=!0;c._old_name=c.innerHTML;c.innerHTML="<input type='text' value='"+c.innerHTML+"' />";var e=c.querySelector("input");e.addEventListener("blur",function(a){var e=a.target.value;
setTimeout(function(){c.innerHTML=e},1);delete c._editing;LiteGUI.trigger(h.root,"item_renamed",{old_name:c._old_name,new_name:e,item:b,data:b.data});delete c._old_name});e.addEventListener("keydown",function(a){13==a.keyCode&&this.blur()});e.focus();a.preventDefault()}a.preventDefault();a.stopPropagation()}function g(a){a.preventDefault()}if(null===a||void 0===a)console.error("Tree item cannot be null");else{b=document.createElement("li");b.className="ltreeitem";var h=this;if(a.id){var k=a.id.replace(/\s/g,
"_");b.className+=" ltreeitem-"+k;b.dataset.item_id=a.id}if(a.dataset)for(var l in a.dataset)b.dataset[l]=a.dataset[l];a.DOM=b;b.data=a;void 0!==c&&(b.dataset.level=c,b.classList.add("ltree-level-"+c));var m=document.createElement("div");m.className="ltreeitemtitle";a.className&&(m.className+=" "+a.className);m.innerHTML="<span class='precontent'></span><span class='indentblock'></span><span class='collapsebox'></span><span class='incontent'></span><span class='postcontent'></span>";c=a.content||
a.id||"";m.querySelector(".incontent").innerHTML=c;a.precontent&&(m.querySelector(".precontent").innerHTML=a.precontent);a.postcontent&&(m.querySelector(".postcontent").innerHTML=a.postcontent);if(a.dataset)for(l in a.dataset)b.dataset[l]=a.dataset[l];b.appendChild(m);b.title_element=m;!1===a.visible&&(b.style.display="none");b.addEventListener("click",d);b.addEventListener("dblclick",f);b.addEventListener("contextmenu",function(a){a.preventDefault();a.stopPropagation();if(2==a.button)return h.onItemContextMenu?
h.onItemContextMenu(a,{item:this,data:this.data}):!1});this.options.allow_drag&&(m.draggable=!0,m.addEventListener("dragstart",function(b){b.dataTransfer.setData("item_id",this.parentNode.dataset.item_id);if(a.onDragData){var c=a.onDragData();if(c)for(var e in c)b.dataTransfer.setData(e,c[e])}}));var p=0;m.addEventListener("dragenter",function(b){b.preventDefault();if(a.skipdrag)return!1;0==p&&m.classList.add("dragover");p++});m.addEventListener("dragleave",function(a){a.preventDefault();p--;0==p&&
m.classList.remove("dragover")});m.addEventListener("dragover",g);m.addEventListener("drop",function(b){m.classList.remove("dragover");b.preventDefault();if(a.skipdrag)return!1;var c=b.dataTransfer.getData("item_id");if(c){var e=this.parentNode.dataset.item_id;(!h.onMoveItem||h.onMoveItem&&!1!=h.onMoveItem(h.getItem(c),h.getItem(e)))&&h.moveItem(c,e)&&LiteGUI.trigger(h.root,"item_moved",{item:h.getItem(c),parent_item:h.getItem(e)})}else LiteGUI.trigger(h.root,"drop_on_item",{item:this,event:b});if(h.onDropItem)h.onDropItem(b,
this.parentNode.data)});return b}};c.prototype.filterByName=function(a){for(var b=0;b<this.root.childNodes.length;++b){var e=this.root.childNodes[b];if(e.classList&&e.classList.contains("ltreeitem")){var d=e.querySelector(".incontent");if(d)if(d=d.innerHTML.toLowerCase(),a&&-1==d.indexOf(a.toLowerCase()))e.classList.add("filtered");else if(e.data&&!1!==e.data.visible&&e.classList.remove("filtered"),d=e.querySelector(".indentblock"))d.style.paddingLeft=a?0:paddingLeft=(parseInt(e.dataset.level)+this.indent_offset)*
c.INDENT+"px"}}};c.prototype.filterByRule=function(a,b){if(!a)throw"filterByRule requires a callback";for(var c=0;c<this.root.childNodes.length;++c){var d=this.root.childNodes[c];if(d.classList&&d.classList.contains("ltreeitem")){var f=d.querySelector(".incontent");if(f)if(a(d.data,f,b)){if(d.data&&!1!==d.data.visible&&d.classList.remove("filtered"),f=d.querySelector(".indentblock"))f.style.paddingLeft=name?0:paddingLeft=(parseInt(d.dataset.level)+this.indent_offset)*LiteGUI.Tree.INDENT+"px"}else d.classList.add("filtered")}}};
c.prototype.getItem=function(a){if(!a)return null;if(a.classList)return a;for(var b=0;b<this.root.childNodes.length;++b){var c=this.root.childNodes[b];if(c.classList&&c.classList.contains("ltreeitem")&&c.dataset.item_id===a)return c}return null};c.prototype.expandItem=function(a,b){var c=this.getItem(a);c&&c.listbox&&(c.listbox.setValue(!0),b&&(c=this.getParent(c))&&this.expandItem(c,b))};c.prototype.collapseItem=function(a){(a=this.getItem(a))&&a.listbox&&listbox.setValue(!1)};c.prototype.isInsideArea=
function(a){a=a.constructor===String?this.getItem(a):a;if(!a)return!1;var b=this.root.getClientRects();if(!b.length)return!1;b=b[0].height;a=a.offsetTop;return this.root.scrollTop<a&&a<this.root.scrollTop+b?!0:!1};c.prototype.scrollToItem=function(a){if(a=a.constructor===String?this.getItem(a):a){var b=this.root.parentNode;if(b){var e=b.getBoundingClientRect();if(e){var d=e.height,f=(parseInt(a.dataset.level)+this.indent_offset)*c.INDENT+50;b.scrollTop=a.offsetTop-0.5*d|0;b.scrollLeft=0.75*e.width<
f?f:0}}}};c.prototype.setSelectedItem=function(a,b,c){if(a){a=this.getItem(a);if(!a)return null;if(!a.classList.contains("selected"))return this.markAsSelected(a),b&&!this._skip_scroll&&this.scrollToItem(a),this.expandItem(a,!0),c&&LiteGUI.trigger(a,"click"),a}else this.unmarkAllAsSelected()};c.prototype.addItemToSelection=function(a){if(a){a=this.getItem(a);if(!a)return null;this.markAsSelected(a,!0);return a}};c.prototype.removeItemFromSelection=function(a){if(a){a=this.getItem(a);if(!a)return null;
a.classList.remove("selected")}};c.prototype.getSelectedItem=function(){return this.root.querySelector(".ltreeitem.selected")};c.prototype.getSelectedItems=function(){return this.root.querySelectorAll(".ltreeitem.selected")};c.prototype.isItemSelected=function(a){return(a=this.getItem(a))?this.isNodeSelected(a):!1};c.prototype.getChildren=function(a,b){a&&a.constructor!==String&&a.dataset&&(a=a.dataset.item_id);return this._findChildElements(a,b)};c.prototype.getParent=function(a){return(a=this.getItem(a))?
this.getItem(a.parent_id):null};c.prototype.getAncestors=function(a,b){b=b||[];var c=this.getItem(a);return c?(b.push(c),this.getAncestors(c.parent_id,b)):b};c.prototype.isAncestor=function(a,b){var c=this.getItem(a);if(!c)return!1;var d=this.getItem(b);return(c=this.getItem(c.parent_id))?c==d?!0:this.isAncestor(c,b):!1};c.prototype.moveItem=function(a,b){if(a===b)return!1;var c=this.getItem(a),d=this.getItem(b);if(this.isAncestor(d,c))return!1;var f=this._findElementIndex(d),g=parseInt(d.dataset.level),
h=this.getParent(c);if(!h)return console.error("node parent not found by id, maybe id has changed"),!1;var k=parseInt(h.dataset.level),f=g-k;if(!d||!c||d==h)return!1;c.parent_id=b;if(g=this.getChildren(c)){g.unshift(c);for(c=0;c<g.length;c++)g[c].parentNode.removeChild(g[c]);for(c=0;c<g.length;c++){var k=g[c],l=parseInt(k.dataset.level)+f;k.dataset.level=l}f=this._findElementIndex(d);l=this._findElementLastChildIndex(f);-1==l&&(l=0);for(c=0;c<g.length;c++)k=g[c],this._insertInside(k,f,l+c-1,parseInt(k.dataset.level))}this._updateListBox(d);
h&&this._updateListBox(h);return!0};c.prototype.removeItem=function(a,b){var c=a;"string"==typeof a&&(c=this.getItem(a));if(!c)return!1;var d=this.getParent(c),f=null;b&&(f=this.getChildren(c));this.root.removeChild(c);if(f)for(c=0;c<f.length;c++)this.root.removeChild(f[c]);d&&this._updateListBox(d);return!0};c.prototype.updateItem=function(a,b){var c=this.getItem(a);if(!c)return!1;c.data=b;b.id&&(c.id=b.id);b.content&&(c.title_element.querySelector(".incontent").innerHTML=b.content);return!0};c.prototype.updateItemId=
function(a,b){var c=this.getItem(a);if(!c)return!1;var d=this.getChildren(a,!0);c.id=b;for(c=0;c<d.length;++c)d[c].parent_id=b;return!0};c.prototype.clear=function(a){if(a){a=this.root.querySelectorAll(".ltreeitem");for(var b=1;b<a.length;b++)this.root.removeChild(a[b])}else this.root.innerHTML=""};c.prototype.getNodeByIndex=function(a){return this.root.querySelectorAll(".ltreeitem")[a]};c.prototype.unmarkAllAsSelected=function(){this.root.classList.remove("selected");var a=this.root.querySelectorAll(".ltreeitem.selected");
if(a)for(var b=0;b<a.length;b++)a[b].classList.remove("selected");a=this.root.querySelectorAll(".ltreeitem.semiselected");for(b=0;b<a.length;b++)a[b].classList.remove("semiselected")};c.prototype.isNodeSelected=function(a){return a.classList.contains("selected")?!0:!1};c.prototype.markAsSelected=function(a,b){if(!a.classList.contains("selected")){b||this.unmarkAllAsSelected();a.classList.add("selected");for(var c=this.getParent(a),d=[];c&&-1==d.indexOf(c);)c.classList.add("semiselected"),d.push(c),
c=this.getParent(c)}};c.prototype._updateListBox=function(a,b,c){if(a){var d=this;if(!a.listbox){var f=a.title_element.querySelector(".collapsebox"),g=LiteGUI.createLitebox(!0,function(b){d.onClickBox(b,a);LiteGUI.trigger(d.root,"item_collapse_change",{item:a,data:g.getValue()})});g.stopPropagation=!0;g.setEmpty(!0);f.appendChild(g);a.listbox=g}(b&&b.collapsed||c>=this.collapsed_depth)&&a.listbox.collapse();(b=this.getChildren(a.dataset.item_id))&&(b.length?a.listbox.setEmpty(!1):a.listbox.setEmpty(!0))}};
c.prototype.onClickBox=function(a,b){var c=this.getChildren(b);if(c)for(var d=0;d<c.length;++d){var f=c[d],g=this.getParent(f),h=!0;g&&(h=this._isNodeChildrenVisible(g));h?f.classList.remove("hidden"):f.classList.add("hidden")}};LiteGUI.Tree=c})();
(function(){function c(a,b){this._ctor(a,b)}c.title_height="20px";c.prototype._ctor=function(a,b){!b&&a&&a.constructor!==String&&(b=a,a=null);b=b||{};this.content=b.content||"";var c=this.root=document.createElement("div");a&&(c.id=a);c.className="litepanel "+(b.className||"");c.data=this;var d="";b.title&&(d+="<div class='panel-header'>"+b.title+"</div>");d+="<div class='content'>"+this.content+"</div>";c.innerHTML=d+"<div class='panel-footer'></div>";b.title&&(this.header=this.root.querySelector(".panel-header"));
this.content=this.root.querySelector(".content");this.footer=this.root.querySelector(".panel-footer");b.width&&(this.root.style.width=LiteGUI.sizeToCSS(b.width));b.height&&(this.root.style.height=LiteGUI.sizeToCSS(b.height));b.position&&(this.root.style.position="absolute",this.root.style.left=LiteGUI.sizeToCSS(b.position[0]),this.root.style.top=LiteGUI.sizeToCSS(b.position[1]));!0==b.scroll&&(this.content.style.overflow="auto")};c.prototype.add=function(a){this.content.appendChild(a.root)};c.prototype.clear=
function(){for(;this.content.firstChild;)this.content.removeChild(this.content.firstChild)};LiteGUI.Panel=c})();
(function(){function c(a,b){if(b||a&&a.constructor===String){var c=a;a=b||{};a.id=c;console.warn("LiteGUI.Dialog legacy parameter, use options as first parameter instead of id.")}this._ctor(a)}c.MINIMIZED_WIDTH=200;c.title_height="20px";c.getDialog=function(a){return(a=document.getElementById(a))?a.dialog:null};c.prototype._ctor=function(a){a=a||{};var b=this;this.width=a.width;this.height=a.height;this.minWidth=a.minWidth||150;this.minHeight=a.minHeight||100;this.content=a.content||"";var e=document.createElement("div");
a.id&&(e.id=a.id);e.className="litedialog "+(a.className||"");e.data=this;e.dialog=this;var d="";if(a.title){d+="<div class='panel-header'>"+a.title+"</div><div class='buttons'>";a.minimize&&(d+="<button class='litebutton mini-button minimize-button'>-</button><button class='litebutton mini-button maximize-button' style='display:none'></button>");a.hide&&(d+="<button class='litebutton mini-button hide-button'></button>");a.detachable&&(d+="<button class='litebutton mini-button detach-button'></button>");
if(a.close||a.closable)d+="<button class='litebutton mini-button close-button'>"+LiteGUI.special_codes.close+"</button>";d+="</div>"}d+="<div class='content'>"+this.content+"</div>";d+="<div class='panel-footer'></div>";e.innerHTML=d;this.root=e;this.content=e.querySelector(".content");this.footer=e.querySelector(".panel-footer");a.fullcontent&&(this.content.style.width="100%",this.content.style.height=a.title?"calc( 100% - "+c.title_height+" )":"100%");if(a.buttons)for(var f in a.buttons)this.addButton(a.buttons[f].name,
a.buttons[f]);!0==a.scroll&&(this.content.style.overflow="auto");(d=e.querySelector(".close-button"))&&d.addEventListener("click",this.close.bind(this));(d=e.querySelector(".maximize-button"))&&d.addEventListener("click",this.maximize.bind(this));(d=e.querySelector(".minimize-button"))&&d.addEventListener("click",this.minimize.bind(this));(d=e.querySelector(".hide-button"))&&d.addEventListener("click",this.hide.bind(this));(e=e.querySelector(".detach-button"))&&e.addEventListener("click",function(){b.detachWindow()});
this.enableProperties(a);this.root.addEventListener("DOMNodeInsertedIntoDocument",function(){if(b.on_attached_to_DOM)b.on_attached_to_DOM();if(b.on_resize)b.on_resize()});this.root.addEventListener("DOMNodeRemovedFromDocument",function(){if(b.on_detached_from_DOM)b.on_detached_from_DOM()});if(a.attach||a.parent)e=null,a.parent&&(e="string"==typeof a.parent?document.querySelector(a.parent):a.parent),e||(e=LiteGUI.root),e.appendChild(this.root),this.center()};c.prototype.add=function(a){this.content.appendChild(a.root||
a)};c.prototype.enableProperties=function(a){a=a||{};var b=this,c=this.root;c.style.position="absolute";c.style.minWidth=this.minWidth+"px";c.style.minHeight=this.minHeight+"px";this.width&&(c.style.width=this.width+"px");this.height&&("number"==typeof this.height?c.style.height=this.height+"px":-1!=this.height.indexOf("%")&&(c.style.height=this.height),this.content.style.height="calc( "+this.height+"px - 24px )");c.style.boxShadow="0 0 3px black";a.draggable&&(this.draggable=!0,LiteGUI.draggable(c,
c.querySelector(".panel-header"),function(){b.bringToFront()},null,function(){return!b.minimized}));a.resizable&&this.setResizable()};c.prototype.setResizable=function(){function a(c){if("mousedown"==c.type)document.body.addEventListener("mousemove",a),document.body.addEventListener("mouseup",a),h=this==d,f[0]=c.pageX,f[1]=c.pageY;else if("mousemove"==c.type){var e=LiteGUI.getRect(b),m=e.width,p=m-(f[0]-c.pageX),e=e.height,r=e-(f[1]-c.pageY);h&&(b.style.width=p+"px");b.style.height=r+"px";f[0]=c.pageX;
f[1]=c.pageY;g.content.style.height="calc( 100% - 24px )";if(g.on_resize&&(m!=p||e!=r))g.on_resize(c,p,r)}else"mouseup"==c.type&&(document.body.removeEventListener("mousemove",a),document.body.removeEventListener("mouseup",a),h=!1);c.preventDefault();c.stopPropagation();return!1}if(!this.resizable){var b=this.root;this.resizable=!0;var c=this.footer;c.style.minHeight="4px";c.classList.add("resizable");var d=document.createElement("div");d.className="resizable-corner";this.root.appendChild(d);c.addEventListener("mousedown",
a);d.addEventListener("mousedown",a,!0);var f=[0,0],g=this,h=!1}};c.prototype.dockTo=function(a,b){if(a){var c=this.root;b=b||"full";a=a.content||a;c.style.top=0;c.style.left=0;c.style.boxShadow="0 0 0";if("full"==b)c.style.position="relative",c.style.width="100%",c.style.height="100%",this.content.style.width="100%",this.content.style.height="calc(100% - "+LiteGUI.Panel.title_height+")",this.content.style.overflow="auto";else if("left"==b||"right"==b)c.style.position="absolute",c.style.top=0,c.style[b]=
0,c.style.width=this.width+"px",c.style.height="100%",this.content.style.height="calc(100% - "+LiteGUI.Panel.title_height+")",this.content.style.overflow="auto","right"==b&&(c.style.left="auto",c.style.right=0);else if("bottom"==b||"top"==b)c.style.width="100%",c.style.height=this.height+"px","bottom"==b&&(c.style.bottom=0,c.style.top="auto");this.draggable&&LiteGUI.draggable(c);a.content?a.content.appendChild(c):"string"==typeof a?(a=document.querySelector(a))&&a.appendChild(c):a.appendChild(c)}};
c.prototype.addButton=function(a,b){b=b||{};b.constructor===Function&&(b={callback:b});var c=this,d=document.createElement("button");d.className="litebutton";d.innerHTML=a;b.className&&(d.className+=" "+b.className);this.root.querySelector(".panel-footer").appendChild(d);d.addEventListener("click",function(a){b.callback&&b.callback(this);b.close&&c.close()});return d};c.prototype.close=function(){LiteGUI.remove(this.root);LiteGUI.trigger(this,"closed",this);if(this.on_close)this.on_close();this.onclose&&
console.warn("Dialog: Do not use onclose, use on_close instead");this.dialog_window&&(this.dialog_window.close(),this.dialog_window=null)};c.prototype.highlight=function(a){a=a||100;this.root.style.outline="1px solid white";var b=this.root.ownerDocument;(b.defaultView||b.parentWindow).focus();setTimeout(function(){this.root.style.outline=null}.bind(this),a)};c.minimized=[];c.prototype.minimize=function(){if(!this.minimized){this.minimized=!0;this.old_box=this.root.getBoundingClientRect();this.root.querySelector(".content").style.display=
"none";var a=this.root.querySelector(".minimize-button");a&&(a.style.display="none");if(a=this.root.querySelector(".maximize-button"))a.style.display="";this.root.style.width=LiteGUI.Dialog.MINIMIZED_WIDTH+"px";LiteGUI.bind(this,"closed",function(){LiteGUI.Dialog.minimized.splice(LiteGUI.Dialog.minimized.indexOf(this),1);LiteGUI.Dialog.arrangeMinimized()});LiteGUI.Dialog.minimized.push(this);LiteGUI.Dialog.arrangeMinimized();LiteGUI.trigger(this,"minimizing")}};c.arrangeMinimized=function(){for(var a in LiteGUI.Dialog.minimized){var b=
LiteGUI.Dialog.minimized[a],c=b.root.parentNode.getBoundingClientRect().height-20;b.root.style.left=LiteGUI.Dialog.MINIMIZED_WIDTH*a;b.root.style.top=c+"px"}};c.prototype.maximize=function(){if(this.minimized){this.minimized=!1;this.root.querySelector(".content").style.display="";LiteGUI.draggable(this.root);this.root.style.left=this.old_box.left+"px";this.root.style.top=this.old_box.top+"px";this.root.style.width=this.old_box.width+"px";this.root.style.height=this.old_box.height+"px";var a=this.root.querySelector(".minimize-button");
a&&(a.style.display="");if(a=this.root.querySelector(".maximize-button"))a.style.display="none";LiteGUI.Dialog.minimized.splice(LiteGUI.Dialog.minimized.indexOf(this),1);LiteGUI.Dialog.arrangeMinimized();LiteGUI.trigger(this,"maximizing")}};c.prototype.makeModal=function(){LiteGUI.showModalBackground(!0);LiteGUI.modalbg_div.appendChild(this.root);this.show();this.center();LiteGUI.bind(this,"closed",function(a){LiteGUI.showModalBackground(!1)})};c.prototype.bringToFront=function(){var a=this.root.parentNode;
a.removeChild(this.root);a.appendChild(this.root)};c.prototype.show=function(a,b){if(!this.root.parentNode){if(b){var c=b.ownerDocument;(c.querySelector(".litegui-wrap")||c.body).appendChild(this.root);(c.defaultView||c.parentWindow).focus()}else LiteGUI.add(this);this.center()}this.detach_window||(this.root.style.display="",LiteGUI.trigger(this,"shown"))};c.prototype.hide=function(a){this.root.style.display="none";LiteGUI.trigger(this,"hidden")};c.prototype.fadeIn=function(a){a=a||1E3;this.root.style.display=
"";this.root.style.opacity=0;var b=this;setTimeout(function(){b.root.style.transition="opacity "+a+"ms";b.root.style.opacity=1},100)};c.prototype.setPosition=function(a,b){this.root.parentNode||console.warn("LiteGUI.Dialog: Cannot set position of dialog if it is not in the DOM");this.root.position="absolute";this.root.style.left=a+"px";this.root.style.top=b+"px"};c.prototype.setSize=function(a,b){this.root.style.width="number"==typeof a?a+"px":a;this.root.style.height="number"==typeof b?b+"px":b};
c.prototype.setTitle=function(a){this.header&&(this.header.innerHTML=a)};c.prototype.center=function(){if(this.root.parentNode){this.root.position="absolute";var a=this.root.offsetHeight,b=this.root.parentNode.offsetHeight;this.root.style.left=Math.floor(0.5*(this.root.parentNode.offsetWidth-this.root.offsetWidth))+"px";this.root.style.top=Math.floor(0.5*(b-a))+"px"}};c.prototype.adjustSize=function(a,b){a=a||0;this.content.style.height="auto";if(0!=this.content.offsetHeight||b){var c=0,d=this.root.querySelector(".panel-footer");
d&&(c+=d.offsetHeight);this.setSize(this.content.offsetWidth,this.content.offsetHeight+20+a+c)}else{var f=this;setTimeout(function(){f.adjustSize(a,!0)},1)}};c.prototype.clear=function(){this.content.innerHTML=""};c.prototype.detachWindow=function(a,b){if(!this.dialog_window){var c=this.root.getClientRects()[0],d=c.width,c=c.height,f="Window",g=this.root.querySelector(".panel-header");g&&(f=g.textContent);var h=window.open("","","width="+d+", height="+c+", location=no, status=no, menubar=no, titlebar=no, fullscreen=yes");
h.document.write("<head><title>"+f+"</title>");this.dialog_window=h;d=document.querySelectorAll("link[rel='stylesheet'],style");for(c=0;c<d.length;c++)h.document.write(d[c].outerHTML);h.document.write("</head><body></body>");h.document.close();h.onbeforeunload=function(){var a=LiteGUI.windows.indexOf(h);-1!=a&&LiteGUI.windows.splice(a,1);b&&b()};h.document.body.appendChild(this.content);this.root.style.display="none";this._old_height=this.content.style.height;this.content.style.height="100%";LiteGUI.windows.push(h);
a&&a();return h}};c.prototype.reattachWindow=function(a){this.dialog_window&&(this.root.appendChild(this.content),this.root.style.display="",this.content.style.height=this._old_height,delete this._old_height,this.dialog_window.close(),a=LiteGUI.windows.indexOf(this.dialog_window),-1!=a&&LiteGUI.windows.splice(a,1),this.dialog_window=null)};c.showAll=function(){for(var a=document.body.querySelectorAll("litedialog"),b=0;b<a.length;b++)a[b].dialog.show()};c.hideAll=function(){for(var a=document.body.querySelectorAll("litedialog"),
b=0;b<a.length;b++)a[b].dialog.hide()};c.closeAll=function(){for(var a=document.body.querySelectorAll("litedialog"),b=0;b<a.length;b++)a[b].dialog.close()};LiteGUI.Dialog=c})();
(function(){function c(a){a=a||{};this.root=document.createElement("table");this.root.classList.add("litetable");this.columns=[];this.column_fields=[];this.rows=[];this.data=[];this._must_update_header=!0;a.colums&&this.setColumns(a.colums);a.scrollable&&(this.root.style.overflow="auto");a.height&&(this.root.style.height=LiteGUI.sizeToCSS(a.height));a.columns&&this.setColumns(a.columns);a.rows&&this.setRows(a.data)}c.prototype.setRows=function(a,b){this.data=a;this.updateContent(b)};c.prototype.addRow=
function(a,b){for(var c=document.createElement("tr"),d=0;d<this.column_fields.length;++d){var f=document.createElement("td"),g=null,g=a.constructor===Array?a[d]:a[this.column_fields[d]];void 0===g&&(g="");f.innerHTML=g;g=this.columns[d];if(void 0===g)break;g.className&&(f.className=g.className);g.width&&(f.style.width=g.width);c.appendChild(f)}this.root.appendChild(c);this.rows.push(c);b||this.data.push(a);return c};c.prototype.updateRow=function(a,b){this.data[a]=b;var c=this.rows[a];if(c){for(var d=
c.querySelectorAll("td"),f=0;f<d.length;++f){var g=this.columns[f],h=null,h=b.constructor===Array?b[f]:b[g.field];void 0===h&&(h="");d[f].innerHTML=h}return c}};c.prototype.updateCell=function(a,b,c){if(a=this.rows[a])if(b=a.childNodes[b])return b.innerHTML=c,b};c.prototype.setColumns=function(a){this.columns.length=0;this.column_fields.length=0;for(var b=Math.floor(100/a.length).toFixed(1)+"%",c=[],d=0;d<a.length;++d){var f=a[d];if(null!==f&&void 0!==f){if(f.constructor===String||f.constructor===
Number)f={name:String(f)};f={name:f.name||"",width:LiteGUI.sizeToCSS(f.width||b),field:(f.field||f.name||"").toLowerCase(),className:f.className};d==a.length-1?f.width=" calc( 100% - ( "+c.join(" + ")+" ) )":c.push(f.width);this.columns.push(f);this.column_fields.push(f.field)}}this._must_update_header=!0;this.updateContent()};c.prototype.updateContent=function(a){this.root.innerHTML="";if(this._must_update_header){this.header=document.createElement("tr");for(var b=0;b<this.columns.length;++b){var c=
this.columns[b],d=document.createElement("th");d.innerHTML=c.name;c.width&&(d.style.width=c.width);c.th=d;this.header.appendChild(d)}this._must_update_header=!1}this.root.appendChild(this.header);if(this.data)if(this.data.length!=this.rows.length&&(a=!1),a)for(b=0;b<this.rows.length;++b)a=this.updateRow(b,this.data[b]),this.root.appendChild(a);else for(b=this.rows.length=0;b<this.data.length;++b)this.addRow(this.data[b],!0)};LiteGUI.Table=c})();
function Inspector(c,a){if(c&&c.constructor===String){var b=c;c=a||{};c.id=b;console.warn("LiteGUI.Inspector legacy parameter, use options as first parameter instead of id.")}c=c||{};this.root=document.createElement("DIV");this.root.className="inspector "+(c.full?"full":"")+(c.className||"");c.one_line&&(this.one_line=!0,this.root.className+=" one_line");c.id&&(this.root.id=c.id);this.sections=[];this.values={};this.widgets=[];this.widgets_by_name={};this.row_number=0;this.addContainer();this.tab_index=
Math.floor(1E4*Math.random());c.width&&(this.root.style.width=LiteGUI.sizeToCSS(c.width));c.height&&(this.root.style.height=LiteGUI.sizeToCSS(c.height),c.one_line||(this.root.style.overflow="auto"));c.name_width&&(this.name_width=c.name_width);c.widgets_width&&(this.widgets_width=c.widgets_width);c.noscroll&&(this.root.style.overflow="hidden");c.onchange&&(this.onchange=c.onchange);c.parent&&this.appendTo(c.parent);this.className=this.root.className;this.widgets_per_row=c.widgets_per_row||1}
Inspector.prototype.getValues=function(){var c={},a;for(a in this.widgets_by_name)c[a]=this.widgets_by_name[a].getValue();return c};Inspector.prototype.setValues=function(c){for(var a in c)this.widgets_by_name[a]&&this.widgets_by_name[a].setValue(c[a])};Inspector.prototype.appendTo=function(c,a){c&&(c.constructor===String&&(c=document.querySelector(c)),c&&(a?c.insertBefore(this.root,c.firstChild):c.appendChild(this.root)))};
Inspector.prototype.clear=function(){for(purgeElement(this.root,!0);this.root.hasChildNodes();)this.root.removeChild(this.root.lastChild);this.root.className=this.className;this.row_number=0;this.values={};this.widgets=[];this.widgets_by_name={};this.sections=[];this._current_container_stack=this._current_container=this.current_section=null;this.addContainer()};Inspector.prototype.refresh=function(){if(this.on_refresh)this.on_refresh()};
Inspector.prototype.append=function(c,a){a=a||{};var b=a.widget_parent||this._current_container||this.root;a.replace?a.replace.parentNode.replaceChild(c,a.replace):(c.section=this.current_section,b.appendChild(c))};Inspector.prototype.pushContainer=function(c){if(this._current_container_stack){if(-1!=this._current_container_stack.indexOf(c)){console.warn("Container already in the stack");return}this._current_container_stack.push(c)}else this._current_container_stack=[c];this._current_container=c};
Inspector.prototype.isContainerInStack=function(c){return this._current_container_stack?-1!=this._current_container_stack.indexOf(c)?!0:!1:!1};
Inspector.prototype.popContainer=function(c){this.row_number=0;if(this._current_container_stack&&this._current_container_stack.length){if(c)for(var a=this._current_container_stack.pop();a&&a!=c;)a=this._current_container_stack.pop();else this._current_container_stack.pop();this._current_container=this._current_container_stack[this._current_container_stack.length-1]}else this._current_container=null};Inspector.prototype.setup=function(c){for(var a in c){var b=c[a];this.add(b.type,b.name,b.value,b.options)}};
Inspector.prototype.getWidget=function(c){return null!==c&&c.constructor===Number?this.widgets[c]:this.widgets_by_name[c]};
Inspector.prototype.inspectInstance=function(c,a,b,e){function d(a,b){b=b||{};for(var c in a)b[c]=a[c];return b}if(c){a||(a=c.getProperties?c.getProperties():this.collectProperties(c));var f=c.constructor;!b&&f.properties&&(b=f.properties);var g={};if(c.getInspectorProperties)g=c.getInspectorProperties();else for(var h in a)if(b&&b[h])g[h]=d(b[h]);else{var k=a[h];if(f["@"+h])(k=f["@"+h])&&null===k.widget||(g[h]=d(k));else if(c["@"+h])g[h]=c["@"+h];else if(null!==k&&void 0!==k)switch(k.constructor){case Number:g[h]=
{type:"number",step:0.1};break;case String:g[h]={type:"string"};break;case Boolean:g[h]={type:"boolean"};break;default:if(k&&(k.constructor===Array||k.constructor.BYTES_PER_ELEMENT)){var l=null!=k[0]&&k[0].constructor===Number;switch(k.length){case 2:g[h]={type:l?"vec2":"Array",step:0.1};break;case 3:g[h]={type:l?"vec3":"Array",step:0.1};break;case 4:g[h]={type:l?"vec4":"Array",step:0.1};break;default:g[h]={type:"Array"}}}}}if(e)for(h in e)delete g[e[h]];if(f.properties_order){a={};for(h in f.properties_order)b=
f.properties_order[h],g[b]?a[b]=g[b]:console.warn("property not found in instance:",b);for(h in g)a[h]||(a[h]=g[h]);g=a}return this.showProperties(c,g)}};Inspector.prototype.collectProperties=function(c){var a={},b;for(b in c)if("_"!=b[0]&&"@"!=b[0]&&"jQuery"!=b.substr(0,6)){var e=c[b];if(!e||e.constructor!=Function||c.constructor["@"+b])a[b]=e}return a};
Inspector.prototype.showProperties=function(c,a){for(var b in a){var e=b,d=a[b];if(d){d.constructor===String&&(d={type:d});d.name&&(e=d.name);if(!d.callback){var f={instance:c,name:e,options:d};"function"!=d.type&&(d.callback=Inspector.assignValue.bind(f))}d.callback_update||(f={instance:c,name:e},d.callback_update=function(){return this.instance[this.name]}.bind(f));d.instance=c;d.varname=e;f=d.widget||d.type||"string";if(this.on_addProperty)this.on_addProperty(f,c,e,c[e],d);this.add(f,e,c[e],d)}}if(c.constructor.widgets)for(b in c.constructor.widgets)e=
c.constructor.widgets[b],this.add(e.widget,e.name,e.value,e);if(c.onShowProperties)c.onShowProperties(this);if(c.constructor.onShowProperties)c.constructor.onShowProperties(c,this)};
Inspector.assignValue=function(c){var a=this.instance,b=a[this.name];if(null==b||null==c||"enum"==this.options.type)a[this.name]=c;else if("number"==typeof b)a[this.name]=parseFloat(c);else if("string"==typeof b)a[this.name]=c;else if(c&&c.length&&b&&b.length&&!(Object.getOwnPropertyDescriptor(a,this.name)&&Object.getOwnPropertyDescriptor(a,this.name).set||Object.getOwnPropertyDescriptor(a.__proto__,this.name)&&Object.getOwnPropertyDescriptor(a.__proto__,this.name).set))for(a=0;a<c.length;++a)b[a]=
c[a];else a[this.name]=c};
Inspector.prototype.createWidget=function(c,a,b){b=b||{};a=void 0===a||null===a?"":a;var e=document.createElement("DIV");e.className="widget "+(b.className||"");e.inspector=this;e.options=b;e.name=c;this.row_number+=this.widgets_per_row;0==this.row_number%2&&(e.className+=" even");var d=b.width||this.widgets_width;d&&(e.style.width=LiteGUI.sizeToCSS(d),e.style.width||(e.style.width="calc("+LiteGUI.sizeToCSS(d)+")"),e.style.minWidth="auto");if(d=b.height||this.height)e.style.height=LiteGUI.sizeToCSS(d),
e.style.height||(e.style.height="calc("+LiteGUI.sizeToCSS(d)+")"),e.style.minHeight="auto";this.widgets.push(e);if(b.widget_name||c)this.widgets_by_name[b.widget_name||c]=e;1!=this.widgets_per_row&&(b.width||(e.style.width=(100/this.widgets_per_row).toFixed(2)+"%"),e.style.display="inline-block");var f=d="";void 0===c||null===c||!this.name_width&&!b.name_width||this.one_line||(f=LiteGUI.sizeToCSS(b.name_width||this.name_width),d="style='width: calc("+f+" - 0px); width: -webkit-calc("+f+" - 0px); width: -moz-calc("+
f+" - 0px); '",f="style='width: calc( 100% - "+f+"); width: -webkit-calc(100% - "+f+"); width: -moz-calc( 100% - "+f+"); '");b.name_width&&(d="style='width: "+LiteGUI.sizeToCSS(b.name_width)+" '");b.content_width&&(f="style='width: "+LiteGUI.sizeToCSS(b.content_width)+" '");var g="",h="",k=this.one_line?"":"<span class='filling'></span>";b.pretitle&&(h=b.pretitle);var l="wcontent ",m=c;b.title&&(m=b.title);null===c||void 0===c?l+=" full":g=""===c?g+("<span class='wname' title='"+m+"' "+d+">"+h+"</span>"):
g+("<span class='wname' title='"+m+"' "+d+">"+h+c+k+"</span>");a.constructor===String||a.constructor===Number||a.constructor===Boolean?e.innerHTML=g+"<span class='info_content "+l+"' "+f+">"+a+"</span>":(e.innerHTML=g+"<span class='info_content "+l+"' "+f+"></span>",(c=e.querySelector("span.info_content"))&&c.appendChild(a));e.content=e.querySelector("span.info_content");e.remove=function(){this.parentNode&&this.parentNode.removeChild(this)};return e};
Inspector.onWidgetChange=function(c,a,b,e,d,f){var g=c.section;e.skip_wchange||(g&&LiteGUI.trigger(g,"wbeforechange",b),LiteGUI.trigger(c,"wbeforechange",b));this.values[a]=b;var h=void 0;e.callback&&(h=d?e.callback.apply(c,b):e.callback.call(c,b,f));e.skip_wchange||(g&&LiteGUI.trigger(g,"wchange",b,c),LiteGUI.trigger(c,"wchange",b,c));if(this.onchange)this.onchange(a,b,c);return h};
Inspector.widget_constructors={"null":"addNull",title:"addTitle",info:"addInfo","default":"addDefault",number:"addNumber",slider:"addSlider",string:"addString",text:"addString",textarea:"addTextarea",color:"addColor","boolean":"addCheckbox",checkbox:"addCheckbox",icon:"addIcon",vec2:"addVector2",vector2:"addVector2",vec3:"addVector3",vector3:"addVector3",vec4:"addVector4",vector4:"addVector4","enum":"addCombo",dropdown:"addCombo",combo:"addCombo",button:"addButton",buttons:"addButtons",file:"addFile",
line:"addLine",list:"addList",tree:"addTree",datatree:"addDataTree",pad:"addPad",array:"addArray",separator:"addSeparator"};Inspector.registerWidget=function(c,a){var b="add"+c.charAt(0).toUpperCase()+c.slice(1);Inspector.prototype[b]=a;Inspector.widget_constructors[c]=b};
Inspector.prototype.add=function(c,a,b,e){if(!c)throw"Inspector: no type specified";1==arguments.length&&"object"==typeof c&&(e=c,c=e.type,a=e.name,b=e.value);var d=LiteGUI.Inspector.widget_constructors[c.toLowerCase()];if(d){if(d.constructor===String&&(d=LiteGUI.Inspector.prototype[d]),d&&d.constructor===Function)return e&&e.constructor===Function&&(e={callback:e}),d.call(this,a,b,e)}else console.warn("LiteGUI.Inspector do not have a widget called",c)};Inspector.prototype.getValue=function(c){return this.values[c]};
Inspector.prototype.applyOptions=function(c,a){c&&a&&(a.className&&(c.className+=" "+a.className),a.id&&(c.id=a.id),a.width&&(c.style.width=LiteGUI.sizeToCSS(a.width)),a.height&&(c.style.height=LiteGUI.sizeToCSS(a.height)))};Inspector.prototype.addSeparator=function(){var c=document.createElement("DIV");c.className="separator";this.append(c);return c};Inspector.prototype.addNull=function(c,a,b){return null};
Inspector.prototype.addDefault=function(c,a,b){return null===a||void 0===a?null:a.constructor===Boolean?this.addCheckbox(c,a,b):a.constructor===String?this.addString(c,a,b):a.constructor===Number?this.addNumber(c,a,b):4==a.length?this.addVector4(c,a,b):3==a.length?this.addVector3(c,a,b):2==a.length?this.addVector2(c,a,b):null};
Inspector.prototype.addString=function(c,a,b){b=this.processOptions(b);a=a||"";var e=this;this.values[c]=a;var d="text";b.password&&(d="password");var f=this.createWidget(c,"<span class='inputfield full "+(b.disabled?"disabled":"")+"'><input type='"+d+"' tabIndex='"+this.tab_index+"' "+(b.focus?"autofocus":"")+" class='text string' value='"+a+"' "+(b.disabled?"disabled":"")+"/></span>",b),g=f.querySelector(".wcontent input");b.placeHolder&&g.setAttribute("placeHolder",b.placeHolder);"right"==b.align&&
(g.style.direction="rtl");g.addEventListener(b.immediate?"keyup":"change",function(a){a=Inspector.onWidgetChange.call(e,f,c,a.target.value,b);void 0!==a&&(this.value=a)});b.callback_enter&&g.addEventListener("keydown",function(a){13==a.keyCode&&(Inspector.onWidgetChange.call(e,f,c,a.target.value,b),b.callback_enter(),a.preventDefault())});this.tab_index+=1;f.setIcon=function(a){a?(g.style.background="transparent url('"+a+"') no-repeat left 4px center",g.style.paddingLeft="1.7em"):(g.style.background=
"",g.style.paddingLeft="")};b.icon&&f.setIcon(b.icon);f.setValue=function(a,b){void 0!==a&&a!==g.value&&(g.value=a,b||LiteGUI.trigger(g,"change"))};f.getValue=function(){return g.value};f.focus=function(){this.querySelector("input").focus()};f.disable=function(){g.disabled=!0};f.enable=function(){g.disabled=!1};this.append(f,b);this.processElement(f,b);return f};
Inspector.prototype.addStringButton=function(c,a,b){b=this.processOptions(b);void 0===a&&(a="");var e=this;this.values[c]=a;var d=this.createWidget(c,"<span class='inputfield button'><input type='text' tabIndex='"+this.tab_index+"' class='text string' value='' "+(b.disabled?"disabled":"")+"/></span><button class='micro'>"+(b.button||"...")+"</button>",b),f=d.querySelector(".wcontent input");f.value=a;f.addEventListener("change",function(a){a=Inspector.onWidgetChange.call(e,d,c,a.target.value,b);void 0!==
a&&(this.value=a)});b.disabled&&f.setAttribute("disabled","disabled");d.setIcon=function(a){a?(f.style.background="transparent url('"+a+"') no-repeat left 4px center",f.style.paddingLeft="1.7em"):(f.style.background="",f.style.paddingLeft="")};b.icon&&d.setIcon(b.icon);var g=d.querySelector(".wcontent button");g.addEventListener("click",function(a){b.callback_button&&b.callback_button.call(d,f.value,a)});b.button_width&&(g.style.width=LiteGUI.sizeToCSS(b.button_width),d.querySelector(".inputfield").style.width=
"calc( 100% - "+g.style.width+" - 6px)");this.tab_index+=1;this.append(d,b);d.setValue=function(a,b){f.value=a;b||LiteGUI.trigger(f,"change")};d.disable=function(){f.disabled=!0;g.disabled=!0};d.enable=function(){f.disabled=!1;g.disabled=!1};d.getValue=function(){return f.value};d.focus=function(){LiteGUI.focus(f)};this.processElement(d,b);return d};
Inspector.prototype.addTextarea=function(c,a,b){b=this.processOptions(b);a=a||"";var e=this;this.values[c]=a;var d=this.createWidget(c,"<span class='inputfield textarea "+(b.disabled?"disabled":"")+"'><textarea tabIndex='"+this.tab_index+"' "+(b.disabled?"disabled":"")+"></textarea></span>",b);this.tab_index++;var f=d.querySelector(".wcontent textarea");f.value=a;f.addEventListener(b.immediate?"keyup":"change",function(a){Inspector.onWidgetChange.call(e,d,c,a.target.value,b,!1,a)});b.callback_keydown&&
f.addEventListener("keydown",b.callback_keydown);b.height&&(f.style.height="calc( "+LiteGUI.sizeToCSS(b.height)+" - 5px )");this.append(d,b);d.setValue=function(b,c){void 0!==b&&b!=f.value&&(a=b,f.value=b,c||LiteGUI.trigger(f,"change"))};d.getValue=function(a){return f.value};d.focus=function(){LiteGUI.focus(f)};d.disable=function(){f.disabled=!0};d.enable=function(){f.disabled=!1};this.processElement(d,b);return d};
Inspector.prototype.addNumber=function(c,a,b){b=this.processOptions(b);a=a||0;var e=this;this.values[c]=a;var d=this.createWidget(c,"",b);this.append(d,b);b.extraclass="full";b.tab_index=this.tab_index;b.full=!0;b.precision=void 0!==b.precision?b.precision:2;b.step=void 0===b.step?0==b.precision?1:0.1:b.step;this.tab_index++;var f=null,f=new LiteGUI.Dragger(a,b);f.root.style.width="calc( 100% - 1px )";d.querySelector(".wcontent").appendChild(f.root);f.root.addEventListener("start_dragging",function(a){this.callback_before&&
this.callback_before.call(d)}.bind(b));d.dragger=f;b.disabled&&f.input.setAttribute("disabled","disabled");var g=d.querySelector("input");g.addEventListener("change",function(a){LiteGUI.trigger(d,"wbeforechange",a.target.value);e.values[c]=a.target.value;if(b.callback){var f=b.callback.call(d,parseFloat(a.target.value));"number"==typeof f&&(this.value=f)}LiteGUI.trigger(d,"wchange",a.target.value);if(e.onchange)e.onchange(c,a.target.value,d)});d.setValue=function(a,c){void 0!==a&&(a=parseFloat(a),
b.precision&&(a=a.toFixed(b.precision)),a+=b.units||"",g.value!=a&&(g.value=a,c||LiteGUI.trigger(g,"change")))};d.setRange=function(a,b){f.setRange(a,b)};d.getValue=function(){return parseFloat(g.value)};d.focus=function(){LiteGUI.focus(g)};d.disable=function(){g.disabled=!0};d.enable=function(){g.disabled=!1};this.processElement(d,b);return d};
Inspector.prototype.addVector2=function(c,a,b){function e(a){this.callback_before&&this.callback_before(a)}b=this.processOptions(b);b.step||(b.step=0.1);a=a||[0,0];var d=this;this.values[c]=a;var f=this.createWidget(c,"",b);b.step=b.step||0.1;b.tab_index=this.tab_index;b.full=!0;this.tab_index++;var g=f.querySelector(".wcontent"),h=new LiteGUI.Dragger(a[0],b);h.root.style.marginLeft=0;h.root.style.width="calc( 50% - 1px )";g.appendChild(h.root);b.tab_index=this.tab_index;this.tab_index++;var k=new LiteGUI.Dragger(a[1],
b);k.root.style.width="calc( 50% - 1px )";g.appendChild(k.root);f.draggers=[h,k];LiteGUI.bind(h.root,"start_dragging",e.bind(b));LiteGUI.bind(k.root,"start_dragging",e.bind(b));var l=f.querySelectorAll("input");for(a=0;a<l.length;++a)l[a].addEventListener("change",function(a){a=[];for(var e=0;e<l.length;e++)a.push(parseFloat(l[e].value));LiteGUI.trigger(f,"wbeforechange",[a]);d.values[c]=a;if(b.callback){var g=b.callback.call(f,a);if("object"==typeof g&&2<=g.length){for(e=0;e<l.length;e++)l[e].value=
g[e];a=g}}LiteGUI.trigger(f,"wchange",[a]);if(d.onchange)d.onchange(c,a,f)});this.append(f,b);f.setValue=function(a,b){a&&(h.getValue()!=a[0]&&h.setValue(a[0],!0),k.getValue()!=a[1]&&k.setValue(a[1],b))};f.setRange=function(a,b){h.setRange(a,b);k.setRange(a,b)};this.processElement(f,b);return f};
Inspector.prototype.addVector3=function(c,a,b){function e(a){this.callback_before&&this.callback_before()}b=this.processOptions(b);b.step||(b.step=0.1);a=a||[0,0,0];var d=this;this.values[c]=a;var f=this.createWidget(c,"",b);b.step=b.step||0.1;b.tab_index=this.tab_index;b.full=!0;this.tab_index++;var g=new LiteGUI.Dragger(a[0],b);g.root.style.marginLeft=0;g.root.style.width="calc( 33% - 1px )";f.querySelector(".wcontent").appendChild(g.root);b.tab_index=this.tab_index;this.tab_index++;var h=new LiteGUI.Dragger(a[1],
b);h.root.style.width="calc( 33% - 1px )";f.querySelector(".wcontent").appendChild(h.root);b.tab_index=this.tab_index;this.tab_index++;var k=new LiteGUI.Dragger(a[2],b);k.root.style.width="calc( 33% - 1px )";f.querySelector(".wcontent").appendChild(k.root);f.draggers=[g,h,k];g.root.addEventListener("start_dragging",e.bind(b));h.root.addEventListener("start_dragging",e.bind(b));k.root.addEventListener("start_dragging",e.bind(b));var l=f.querySelectorAll("input");for(a=0;a<l.length;++a)l[a].addEventListener("change",
function(a){a=[];for(var e=0;e<l.length;e++)a.push(parseFloat(l[e].value));LiteGUI.trigger(f,"wbeforechange",[a]);d.values[c]=a;if(b.callback){var g=b.callback.call(f,a);if("object"==typeof g&&3<=g.length){for(e=0;e<l.length;e++)l[e].value=g[e];a=g}}LiteGUI.trigger(f,"wchange",[a]);if(d.onchange)d.onchange(c,a,f)});this.append(f,b);f.setValue=function(a,b){a&&(g.setValue(a[0],!0),h.setValue(a[1],!0),k.setValue(a[2],b))};f.setRange=function(a,b){g.setRange(a,b);h.setRange(a,b);k.setRange(a,b)};this.processElement(f,
b);return f};
Inspector.prototype.addVector4=function(c,a,b){function e(a){this.callback_before&&this.callback_before()}b=this.processOptions(b);b.step||(b.step=0.1);a=a||[0,0,0];var d=this;this.values[c]=a;var f=this.createWidget(c,"",b);b.step=b.step||0.1;b.tab_index=this.tab_index;b.full=!0;this.tab_index++;for(var g=f.draggers=[],h=0;4>h;h++){var k=new LiteGUI.Dragger(a[h],b);k.root.style.marginLeft=0;k.root.style.width="calc( 25% - 1px )";f.querySelector(".wcontent").appendChild(k.root);b.tab_index=this.tab_index;
this.tab_index++;k.root.addEventListener("start_dragging",e.bind(b));g.push(k)}for(var l=f.querySelectorAll("input"),h=0;h<l.length;++h)l[h].addEventListener("change",function(a){a=[];for(var e=0;e<l.length;e++)a.push(parseFloat(l[e].value));LiteGUI.trigger(f,"wbeforechange",[a]);d.values[c]=a;if(b.callback){var g=b.callback.call(f,a);if("object"==typeof g&&4<=g.length){for(e=0;e<l.length;e++)l[e].value=g[e];a=g}}LiteGUI.trigger(f,"wchange",[a]);if(d.onchange)d.onchange(c,a,f)});this.append(f,b);
f.setValue=function(a,b){if(a)for(var c=0;c<g.length;c++)g[c].setValue(a[c],b)};f.setRange=function(a,b){for(var c in g)g[c].setRange(a,b)};this.processElement(f,b);return f};
Inspector.prototype.addPad=function(c,a,b){b=this.processOptions(b);b.step||(b.step=0.1);a=a||[0,0];var e=this;this.values[c]=a;var d=this.createWidget(c,"",b);b.step=b.step||0.1;b.tab_index=this.tab_index;b.full=!0;this.tab_index++;var f=b.minx||b.min||0,g=b.miny||b.min||0,h=b.maxx||b.max||1,k=b.maxy||b.max||1,l=d.querySelector(".wcontent"),m=document.createElement("div");m.className="litepad";l.appendChild(m);m.style.width="100%";m.style.height="100px";b.background&&(m.style.backgroundImage="url('"+
b.background+"')",m.style.backgroundSize="100%",m.style.backgroundRepeat="no-repeat");var p=document.createElement("div");p.className="litepad-handler";m.appendChild(p);b.tab_index=this.tab_index;this.tab_index++;m._onMouseEvent=function(a){var l=m.getBoundingClientRect();a.mousex=a.pageX-l.left;a.mousey=a.pageY-l.top;a.preventDefault();a.stopPropagation();if("mousedown"==a.type)document.body.addEventListener("mousemove",m._onMouseEvent),document.body.addEventListener("mouseup",m._onMouseEvent);else if("mousemove"==
a.type){var p=a.mousex/l.width;a=a.mousey/l.height;p=p*(h-f)+f;a=a*(k-g)+f;p=[p,a];LiteGUI.trigger(d,"wbeforechange",[p]);d.setValue(p);if(b.callback&&(a=b.callback.call(d,p))&&2<=a.length)for(l=0;l<elems.length;l++)d.setValue(a);LiteGUI.trigger(d,"wchange",[p]);if(e.onchange)e.onchange(c,p,d)}else"mouseup"==a.type&&(document.body.removeEventListener("mousemove",m._onMouseEvent),document.body.removeEventListener("mouseup",m._onMouseEvent));return!0};m.addEventListener("mousedown",m._onMouseEvent);
d.setValue=function(a,b){if(void 0!==a){var c=m.getBoundingClientRect(),d=(a[0]-f)/(h-f),e=(a[1]-g)/(k-g),d=Math.max(0,Math.min(d,1)),e=Math.max(0,Math.min(e,1)),l=(c.height-10)/c.height*100;p.style.left=((c.width-10)/c.width*d*100).toFixed(1)+"%";p.style.top=(e*l).toFixed(1)+"%"}};this.append(d,b);d.setValue(a);this.processElement(d,b);return d};
Inspector.prototype.addInfo=function(c,a,b){b=this.processOptions(b);a=void 0===a||null===a?"":a;var e=null;null!=c?e=this.createWidget(c,a,b):(e=document.createElement("div"),b.className&&(e.className=b.className),void 0!==a.nodeName?(e.innerHTML="<span class='winfo'></span>",e.childNodes[0].appendChild(a)):e.innerHTML="<span class='winfo'>"+a+"</span>");var d=e.querySelector(".winfo")||e.querySelector(".wcontent");b.callback&&e.addEventListener("click",b.callback.bind(e));e.setValue=function(a){void 0!==
a&&d&&(d.innerHTML=a)};var f=e.querySelector("span.info_content");f||(f=e.querySelector(".winfo"));b.width&&(e.style.width=LiteGUI.sizeToCSS(b.width),e.style.display="inline-block",c||(d.style.margin="2px"));b.height&&(f.style.height=LiteGUI.sizeToCSS(b.height),f.style.overflow="auto");e.scrollToBottom=function(){f.scrollTop=f.offsetTop};e.add=function(a){f.appendChild(a)};this.append(e,b);this.processElement(e,b);return e};
Inspector.prototype.addSlider=function(c,a,b){b=this.processOptions(b);void 0===b.min&&(b.min=0);void 0===b.max&&(b.max=1);void 0===b.step&&(b.step=0.01);var e=this;if(void 0===a||null===a)a=0;this.values[c]=a;var d=this.createWidget(c,"<span class='inputfield full'>\t\t\t\t<input tabIndex='"+this.tab_index+"' type='text' class='slider-text fixed liteslider-value' value='' /><span class='slider-container'></span></span>",b),f=d.querySelector(".slider-container"),g=new LiteGUI.Slider(a,b);f.appendChild(g.root);
var h=d.querySelector(".slider-text");h.value=a;h.addEventListener("change",function(f){a=f=parseFloat(this.value);g.setValue(f);Inspector.onWidgetChange.call(e,d,c,f,b)});g.onChange=function(a){h.value=a;Inspector.onWidgetChange.call(e,d,c,a,b)};this.append(d,b);d.setValue=function(b,c){void 0!==b&&(a=b,g.setValue(b,c))};d.getValue=function(){return a};this.processElement(d,b);return d};
Inspector.prototype.addCheckbox=function(c,a,b){b=this.processOptions(b);a=!!a;var e=this;this.values[c]=a;var d=b.label_on||b.label||"on",f=b.label_off||b.label||"off",g=this.createWidget(c,"<span class='inputfield'><span tabIndex='"+this.tab_index+"' class='fixed flag checkbox "+(a?"on":"off")+"'>"+(a?d:f)+"</span></span>",b);this.tab_index++;var h=g.querySelector(".wcontent .checkbox");h.addEventListener("keypress",function(a){32==a.keyCode&&LiteGUI.trigger(this,"click")});g.addEventListener("click",
function(){a=!a;g.querySelector("span.flag").innerHTML=a?d:f;a?h.classList.add("on"):h.classList.remove("on");Inspector.onWidgetChange.call(e,g,c,a,b)});g.getValue=function(){return a};g.setValue=function(b,d){void 0!==b&&(a=b,e.values[c]==b||d||LiteGUI.trigger(h,"click"))};this.append(g,b);this.processElement(g,b);return g};
Inspector.prototype.addFlags=function(c,a,b){var e={},d;for(d in c)e[d]=c[d];if(a)for(d in a)"undefined"==typeof e[d]&&(e[d]=a[d]?!0:!1);for(d in e){a={};for(var f in b)a[f]=b[f];a.callback=function(a){return function(b){c[a]=b}}(d);this.addCheckbox(d,e[d],a)}};
Inspector.prototype.addCombo=function(c,a,b){function e(b,c){b||(b=[]);g=b;c&&(a=c);var d="",e=0,h;for(h in g){var k=g[h],s=g.constructor===Array?e:h,t=g.constructor===Array?k:h;k&&k.title&&(t=k.title);d+="<option value='"+s+"' "+(k==a?" selected":"")+" data-index='"+s+"'>"+t+"</option>";e++}f.querySelector("select").innerHTML=d}b=this.processOptions(b);var d=this;this.values[c]=a;this.tab_index++;var f=this.createWidget(c,"<span class='inputfield full inputcombo "+(b.disabled?"disabled":"")+"'></span>",
b);f.options=b;var g=b.values||[];g.constructor===Function&&(g=b.values());var h="<select tabIndex='"+this.tab_index+"' "+(b.disabled?"disabled":"")+" class='"+(b.disabled?"disabled":"")+"'></select>";f.querySelector("span.inputcombo").innerHTML=h;e(g);var k=!1;f.querySelector(".wcontent select").addEventListener("change",function(e){a=g[e.target.value];k||Inspector.onWidgetChange.call(d,f,c,a,b)});f.getValue=function(){return a};f.setValue=function(b,c){if(void 0!==b){a=b;var d=f.querySelector("select"),
e=d.querySelectorAll("option"),h=-1;if(g.constructor===Array)h=g.indexOf(b);else{var q=0,s;for(s in g)if(g[q]==b){h=q;break}else q++}if(-1!=h){k=c;for(s in e)(q=e[s])&&q.dataset&&(parseFloat(q.dataset.index)==h?(q.setAttribute("selected",!0),d.selectedIndex=h):q.removeAttribute("selected"));k=!1}}};f.setOptionValues=e;this.append(f,b);this.processElement(f,b);return f};
Inspector.prototype.addComboButtons=function(c,a,b){b=this.processOptions(b);a=a||"";var e=this;this.values[c]=a;var d="";if(b.values)for(var f in b.values)d+="<button class='wcombobutton "+(a==b.values[f]?"selected":"")+"' data-name='options.values[i]'>"+b.values[f]+"</button>";var g=this.createWidget(c,d,b);a=g.querySelectorAll(".wcontent button");LiteGUI.bind(a,"click",function(a){a=a.target.innerHTML;e.values[c]=a;for(var d=g.querySelectorAll(".selected"),f=0;f<d.length;++f)d[f].classList.remove("selected");
this.classList.add("selected");Inspector.onWidgetChange.call(e,g,c,a,b)});this.append(g,b);this.processElement(g,b);return g};
Inspector.prototype.addTags=function(c,a,b){function e(a){if(!g.tags[a]){LiteGUI.trigger(g,"wbeforechange",g.tags);g.tags[a]=!0;var e=document.createElement("div");e.data=a;e.className="wtag";e.innerHTML=a+"<span class='close'>X</span>";e.querySelector(".close").addEventListener("click",function(a){a=this.parentNode.data;delete g.tags[a];LiteGUI.remove(this.parentNode);LiteGUI.trigger(g,"wremoved",a);Inspector.onWidgetChange.call(d,g,c,g.tags,b)});g.querySelector(".wtagscontainer").appendChild(e);
d.values[c]=g.tags;b.callback&&b.callback.call(g,g.tags);LiteGUI.trigger(g,"wchange",g.tags);LiteGUI.trigger(g,"wadded",a);if(d.onchange)d.onchange(c,g.tags,g)}}b=this.processOptions(b);a=a||[];var d=this;this.values[c]=a;a="<select>";if(b.values)for(var f in b.values)a+="<option>"+b.values[f]+"</option>";var g=this.createWidget(c,"<span class='inputfield full'>"+(a+"</select><div class='wtagscontainer inputfield'></div>")+"</span>",b);g.tags={};for(f in b.value)e(b.value[f]);g.querySelector(".wcontent select").addEventListener("change",
function(a){e(a.target.value)});this.append(g,b);this.processElement(g,b);return g};
Inspector.prototype.addList=function(c,a,b){function e(c){var d=l.querySelector("li.selected");if(d){if(13==c.keyCode){if(!d)return;d=a[d.dataset.pos];b.callback_dblclick&&b.callback_dblclick.call(h,d)}else if(40==c.keyCode){var e=d.nextSibling;e&&LiteGUI.trigger(e,"click");d.scrollIntoViewIfNeeded&&d.scrollIntoViewIfNeeded({block:"end",behavior:"smooth"})}else if(38==c.keyCode)(e=d.previousSibling)&&LiteGUI.trigger(e,"click"),d.scrollIntoViewIfNeeded&&d.scrollIntoViewIfNeeded({block:"end",behavior:"smooth"});
else return;c.preventDefault();c.stopPropagation();return!0}}function d(d){if(b.multiselection)this.classList.toggle("selected");else{d=l.querySelectorAll("li");for(var e=0;e<d.length;++e)d[e].classList.remove("selected");this.classList.add("selected")}d=a[this.dataset.pos];Inspector.onWidgetChange.call(h,l,c,d,b);LiteGUI.trigger(l,"wadded",d)}function f(c){c=a[this.dataset.pos];b.callback_dblclick&&b.callback_dblclick.call(h,c)}function g(a,c,e){var g=e;c=!!c;var h=null,k="";null!=a&&(a.constructor===
String||a.constructor===Number||a.constructor===Boolean?g=String(a):a&&(g=a.content||a.title||a.name||e,h=a.style,a.icon&&(k="<img src='"+a.icon+"' class='icon' /> "),a.selected&&(c=!0)));var l;l=g.replace(/<(?:.|\n)*?>/gm,"");var m=document.createElement("li");m.classList.add("item-"+LiteGUI.safeName(e));c&&m.classList.add("selected");m.dataset.name=l;m.dataset.pos=e;m.value=a;h&&m.setAttribute("style",h);m.innerHTML=k+g;m.addEventListener("click",d);b.callback_dblclick&&m.addEventListener("dblclick",
f);return m}b=this.processOptions(b);var h=this,k="";b.height&&(k="style='height: 100%; overflow: auto;'");k="<ul class='lite-list' "+k+" tabIndex='"+this.tab_index+"'><ul>";this.tab_index++;var l=this.createWidget(c,"<span class='inputfield full "+(b.disabled?"disabled":"")+"' style='height: 100%;'>"+k+"</span>",b);l.querySelector(".info_content").style.height="100%";l.querySelector(".lite-list");k=l.querySelector(".inputfield");k.style.height="100%";k.style.paddingBottom="0.2em";for(var k=l.querySelectorAll("ul"),
m=0;m<k.length;++m){var p=k[m];p.addEventListener("focus",function(){document.addEventListener("keydown",e,!0)});p.addEventListener("blur",function(){document.removeEventListener("keydown",e,!0)})}l.updateItems=function(c,e){e=e||b.selected;a=c;var f=this.querySelector("ul");f.innerHTML="";if(a)for(var h in a){var k=g(a[h],e,h);f.appendChild(k)}LiteGUI.bind(f.querySelectorAll("li"),"click",d)};l.addItem=function(b,c,d){a.constructor!==Array?console.error("cannot add item to list of object, only array"):
(a.push(b),d=this.querySelector("ul"),b=g(b,c),d.appendChild(b))};l.removeItem=function(a){for(var b=l.querySelectorAll(".wcontent li"),c=0;c<b.length;c++)b[c].dataset.name==a&&LiteGUI.remove(b[c])};l.updateItems(a,b.selected);this.append(l,b);l.getSelected=function(){for(var a=[],b=this.querySelectorAll("ul li.selected"),c=0;c<b.length;++c)a.push(b[c].dataset.name);return a};l.getByIndex=function(a){return this.querySelectorAll("ul li")[a]};l.getIndex=l.getByIndex;l.selectIndex=function(a,b){for(var c=
this.querySelectorAll("ul li"),d=0;d<c.length;++d){var e=c[d];d==a?e.classList.add("selected"):b||e.classList.remove("selected")}return c[a]};l.deselectIndex=function(a){(a=this.querySelectorAll("ul li")[a])&&a.classList.remove("selected");return a};l.scrollToIndex=function(a){if(a=this.querySelectorAll("ul li")[a])this.scrollTop=a.offsetTop};l.selectAll=function(){for(var a=this.querySelectorAll("ul li"),b=0;b<a.length;++b){var c=a[b];c.classList.contains("selected")||LiteGUI.trigger(c,"click")}};
l.deselectAll=function(){for(var a=this.querySelectorAll("ul li"),b=0;b<a.length;++b){var c=a[b];c.classList.contains("selected")&&LiteGUI.trigger(c,"click")}};l.setValue=function(a){void 0!==a&&this.updateItems(a)};l.getNumberOfItems=function(){return this.querySelectorAll("ul li").length};l.filter=function(a,b){var c=this.querySelectorAll("ul li"),d=!1;if(a&&a.constructor===String){var e=a;b&&e.toLowerCase();d=!0;a=function(a){return-1!=(b?a:a.toLowerCase()).indexOf(e)}}for(var f=0;f<c.length;++f){var g=
c[f];if(a){var h=g.value;d&&null!=h&&h.constructor!==String&&(h=g.innerHTML);a(h,g,g.classList.contains("selected"))?g.style.display="":g.style.display="none"}else g.style.display=""}};l.selectByFilter=function(a){for(var b=this.querySelectorAll("ul li"),c=0;c<b.length;++c){var d=b[c],e=a(d.value,d,d.classList.contains("selected"));!0===e?d.classList.add("selected"):!1===e&&d.classList.remove("selected")}};b.height&&(l.scrollTop=0);this.processElement(l,b);return l};
Inspector.prototype.addButton=function(c,a,b){b=this.processOptions(b);a=b.button_text||a||"";var e=this,d="";null===c&&(d="single");b.micro&&(d+=" micro");var f="";b.disabled&&(f="disabled='disabled'");var g=b.title||"",h=this.createWidget(c,"<button tabIndex='"+this.tab_index+"' "+f+"></button>",b);this.tab_index++;var k=h.querySelector("button");k.setAttribute("title",g);k.className="litebutton "+d;k.innerHTML=a;k.addEventListener("click",function(d){Inspector.onWidgetChange.call(e,h,c,this.innerHTML,
b,!1,d);LiteGUI.trigger(k,"wclick",a)});this.append(h,b);h.wclick=function(a){b.disabled||LiteGUI.bind(this,"wclick",a)};h.setValue=function(a){void 0!==a&&(k.innerHTML=a)};h.disable=function(){k.disabled=!0};h.enable=function(){k.disabled=!1};this.processElement(h,b);return h};
Inspector.prototype.addButtons=function(c,a,b){b=this.processOptions(b);a=a||"";var e=this,d="",f="calc( "+(100/a.length).toFixed(3)+"% - 4px )",f="width:"+f+"; width: -moz-"+f+"; width: -webkit-"+f+"; margin: 2px;";if(a&&"object"==typeof a)for(var g in a){var h="";b.title&&b.title.constructor===Array&&(h=b.title[g]||"");d+="<button class='litebutton' title='"+h+"' tabIndex='"+this.tab_index+"' style='"+f+"'>"+a[g]+"</button>";this.tab_index++}var k=this.createWidget(c,d,b);a=k.querySelectorAll("button");
for(g=0;g<a.length;++g)a[g].addEventListener("click",function(a){Inspector.onWidgetChange.call(e,k,c,this.innerHTML,b,null,a);LiteGUI.trigger(k,"wclick",this.innerHTML)});this.append(k,b);this.processElement(k,b);return k};
Inspector.prototype.addIcon=function(c,a,b){b=this.processOptions(b);a=a||"";var e=this,d=b.image,f=b.width||b.size||20,g=b.height||b.size||20,h=this.createWidget(c,"<span class='icon' "+(b.title?"title='"+b.title+"'":"")+" tabIndex='"+this.tab_index+"'></span>",b);this.tab_index++;var k=h.querySelector("span.wcontent"),l=h.querySelector("span.icon"),m=b.x||0;b.index&&(m=b.index*-f);h.style.minWidth=h.style.width=f+"px";h.style.margin="0 2px";h.style.padding="0";k.style.margin="0";k.style.padding=
"0";l.style.display="inline-block";l.style.cursor="pointer";l.style.width=f+"px";l.style.height=g+"px";l.style.backgroundImage="url('"+d+"')";l.style.backgroundPosition=m+"px "+(a?g:0)+"px";l.addEventListener("mousedown",function(d){d.preventDefault();a=!a;d=Inspector.onWidgetChange.call(e,h,c,a,b);LiteGUI.trigger(h,"wclick",a);void 0!==d&&(a=d);l.style.backgroundPosition=m+"px "+(a?g:0)+"px";!1===b.toggle&&setTimeout(function(){l.style.backgroundPosition=m+"px 0px";a=!1},200)});this.append(h,b);
h.setValue=function(d,f){void 0!==d&&(a=d,l.style.backgroundPosition=m+"px "+(a?g:0)+"px",f||Inspector.onWidgetChange.call(e,h,c,a,b))};h.getValue=function(){return a};this.processElement(h,b);return h};
Inspector.prototype.addColor=function(c,a,b){b=this.processOptions(b);a=a||[0,0,0];var e=this;this.values[c]=a;var d="<input tabIndex='"+this.tab_index+"' id='colorpicker-"+c+"' class='color' value='"+(a[0]+","+a[1]+","+a[2])+"' "+(b.disabled?"disabled":"")+"/>";this.tab_index++;b.show_rgb&&(d+="<span class='rgb-color'>"+Inspector.parseColor(a)+"</span>");var f=this.createWidget(c,d,b);this.append(f,b);var d=f.querySelector("input.color"),g=null;if(window.jscolor){g=new jscolor.color(d);g.pickerFaceColor=
"#333";g.pickerBorderColor="black";g.pickerInsetColor="#222";g.rgb_intensity=1;b.disabled&&(g.pickerOnfocus=!1);a.constructor!==String&&a.length&&2<a.length&&(g.fromRGB(1*a[0],1*a[1],1*a[2]),g.rgb_intensity=1);d.addEventListener("change",function(a){if(a=f.querySelector(".rgb-color"))a.innerHTML=LiteGUI.Inspector.parseColor(g.rgb)});g.onImmediateChange=function(){var a=[g.rgb[0]*g.rgb_intensity,g.rgb[1]*g.rgb_intensity,g.rgb[2]*g.rgb_intensity],d=[a.concat(),g.toString()];LiteGUI.trigger(f,"wbeforechange",
d);e.values[c]=a;b.callback&&b.callback.call(f,a.concat(),"#"+g.toString(),g);LiteGUI.trigger(f,"wchange",d);if(e.onchange)e.onchange(c,a.concat(),f)};b.step=b.step||0.01;b.dragger_class="nano";var h=new LiteGUI.Dragger(1,b);f.querySelector(".wcontent").appendChild(h.root);h.input.addEventListener("change",function(a){a=parseFloat(this.value);g.rgb_intensity=a;if(g.onImmediateChange)g.onImmediateChange()});f.setValue=function(a,b){g.fromRGB(a[0],a[1],a[2]);b||LiteGUI.trigger(h.input,"change")};f.getValue=
function(){return a}}else d.addEventListener("change",function(a){if(a=f.querySelector(".rgb-color"))a.innerHTML=LiteGUI.Inspector.parseColor(g.rgb)});this.processElement(f,b);return f};
Inspector.prototype.addFile=function(c,a,b){b=this.processOptions(b);a=a||"";var e=this;this.values[c]=a;var d=this.createWidget(c,"<span class='inputfield full whidden' style='width: calc(100% - 26px)'><span class='filename'></span></span><button class='litebutton' style='width:20px; margin-left: 2px;'>...</button><input type='file' size='100' class='file' value='"+a+"'/>",b);d.querySelector(".wcontent").style.position="relative";var f=d.querySelector(".wcontent input"),g=d.querySelector(".wcontent .filename");
a&&(g.innerText=a.name);f.addEventListener("change",function(a){if(a.target.files.length){var f=a.target.files[0];f.files=a.target.files;b.generate_url&&(f.url=URL.createObjectURL(a.target.files[0]));g.innerText=f.name;b.read_file?(a=new FileReader,a.onload=function(a){f.data=a.target.result;Inspector.onWidgetChange.call(e,d,c,f,b)},"binary"==b.read_file?a.readAsArrayBuffer(f):"data_url"==b.read_file?a.readAsDataURL(f):a.readAsText(f)):Inspector.onWidgetChange.call(e,d,c,f,b)}else g.innerText="",
Inspector.onWidgetChange.call(e,d,c,null,b)});this.append(d,b);return d};
Inspector.prototype.addLine=function(c,a,b){b=this.processOptions(b);a=a||"";var e=this;this.values[c]=a;var d=this.createWidget(c,"<span class='line-editor'></span>",b);d.style.width="100%";a=new LiteGUI.LineEditor(a,b);d.querySelector("span.line-editor").appendChild(a);LiteGUI.bind(a,"change",function(a){LiteGUI.trigger(d,"wbeforechange",[a.target.value]);b.callback&&b.callback.call(d,a.target.value);LiteGUI.trigger(d,"wchange",[a.target.value]);Inspector.onWidgetChange.call(e,d,c,a.target.value,
b)});this.append(d,b);return d};
Inspector.prototype.addTree=function(c,a,b){b=this.processOptions(b);a=a||"";var e=this.createWidget(c,"<div class='wtree inputfield full'></div>",b);c=e.querySelector(".wtree");b.height&&(c.style.height="number"==typeof b.height?b.height+"px":b.height,c.style.overflow="auto");var d=e.tree=new LiteGUI.Tree(a,b.tree_options);d.onItemSelected=function(a,c){b.callback&&b.callback.call(e,a,c)};c.appendChild(d.root);e.setValue=function(a){d.updateTree(a)};this.append(e,b);this.processElement(e,b);return e};
Inspector.prototype.addDataTree=function(c,a,b){function e(a,b){for(var c in b){var d=document.createElement("div");d.className="treenode";"object"==typeof b[c]?(d.innerHTML="<span class='itemname'>"+c+"</span><span class='itemcontent'></span>",e(d.querySelector(".itemcontent"),b[c])):d.innerHTML="<span class='itemname'>"+c+"</span><span class='itemvalue'>"+b[c]+"</span>";a.appendChild(d)}}b=this.processOptions(b);a=a||"";c=this.createWidget(c,"<div class='wtree'></div>",b);var d=c.querySelector(".wtree");
e(d,a);this.append(c,b);return c};
Inspector.prototype.addArray=function(c,a,b){function e(){var a=this.value,c=Math.min(a.length,h);f.widgets_per_row+=1;this.innerHTML="";for(var e=0;e<c;++e){var k=null;void 0!==a[e]&&(k=a[e]);var l=document.createElement("div");l.className="array-row";l.innerHTML="<span class='row-index'>"+e+"</span><span class='row-cell'></span><button style='width: 30px;' class='litebutton single row-trash'><img src='imgs/mini-icon-trash.png'/></button>";this.appendChild(l);l={widget_parent:l.querySelector(".row-cell"),
callback:d.bind({value:this.value,index:e})};if(b.data_options)for(var s in b.data_options)l[s]=b.data_options[s];f.add(g,null,k,l)}f.widgets_per_row-=1}function d(a){this.value[this.index]=a;b.callback&&b.callback.call(k,this.value,this.index)}var f=this;if(a&&a.constructor===Array){b=this.processOptions(b);var g=b.data_type||"string",h=b.max_items||100,k=null;this.widgets_per_row=3;this.addInfo(c,null,{name_width:"100%",width:"100% - 160px"});var l=this.addString("length",a.length||"0",{width:100,
callback:function(b){b=parseInt(b);0>a&&(a=0);a.length=b;e.call(k)}});this.addButtons(null,["+","-"],{width:60,callback:function(b){"+"==b?a.length+=1:0<a.length&&(a.length-=1);l.setValue(a.length);e.call(k)}});this.widgets_per_row=1;k=this.addContainer(c,b);k.value=a;e.call(k);k.setValue=function(a){this.value=a;e.call(k)};k.getValue=function(){return this.value=v};return k}console.error("Inspector: Array widget value must be a valid array")};
Inspector.prototype.addContainer=function(c,a){c&&c.constructor!==String&&console.warn("LiteGUI.Inspector.addContainer first parameter must be a string with the name");var b=this.startContainer(null,a);this.endContainer();return b};
Inspector.prototype.startContainer=function(c,a){a=this.processOptions(a);var b=document.createElement("DIV");b.className="wcontainer";this.applyOptions(b,a);this.row_number=0;this.append(b);this.pushContainer(b);a.widgets_per_row&&(this.widgets_per_row=a.widgets_per_row);a.height&&(b.style.height=LiteGUI.sizeToCSS(a.height),b.style.overflow="auto");b.refresh=function(){b.on_refresh&&b.on_refresh.call(this,b)};return b};Inspector.prototype.endContainer=function(c,a){this.popContainer()};
Inspector.prototype.addSection=function(c,a){a=this.processOptions(a);var b=this;this.current_section&&this.current_section.end();var e=document.createElement("DIV");e.className="wsection";c||(e.className+=" notitle");a.className&&(e.className+=" "+a.className);a.collapsed&&(e.className+=" collapsed");a.id&&(e.id=a.id);a.instance&&(e.instance=a.instance);var d="";c&&(d+="<div class='wsectiontitle'>"+(a.no_collapse?"":"<span class='switch-section-button'></span>")+c+"</div>");e.innerHTML=d+"<div class='wsectioncontent'></div>";
e._last_container_stack=this._current_container_stack.concat();this.root.appendChild(e);this.sections.push(e);e.sectiontitle=e.querySelector(".wsectiontitle");c&&e.sectiontitle.addEventListener("click",function(b){"button"!=b.target.localName&&(e.classList.toggle("collapsed"),b=e.querySelector(".wsectioncontent"),b.style.display="none"===b.style.display?null:"none",a.callback&&a.callback.call(e,!e.classList.contains("collapsed")))});a.collapsed&&(e.querySelector(".wsectioncontent").style.display=
"none");this.setCurrentSection(e);a.widgets_per_row&&(this.widgets_per_row=a.widgets_per_row);e.refresh=function(){e.on_refresh&&e.on_refresh.call(this,e)};e.end=function(){if(b.current_section==this){b._current_container_stack=this._last_container_stack;b._current_container=null;var a=this.querySelector(".wsectioncontent");a&&(b.isContainerInStack(a)&&b.popContainer(a),b.current_section=null)}};return e};
Inspector.prototype.setCurrentSection=function(c){this.current_section!=c&&(this.current_section=c,this.popContainer(c.parentNode),c=c.querySelector(".wsectioncontent"),this.pushContainer(c))};Inspector.prototype.getCurrentSection=function(){for(var c=this._current_container_stack.length-1;0<=c;--c){var a=this._current_container_stack[c];if(a.classList.contains("wsectioncontent"))return a.parentNode}return null};Inspector.prototype.endCurrentSection=function(){this.current_section&&this.current_section.end()};
Inspector.prototype.beginGroup=function(c,a){a=this.processOptions(a);var b=document.createElement("DIV");b.className="wgroup";b.innerHTML="<div class='wgroupheader "+(a.title?"wtitle":"")+"'><span class='switch-section-button'></span>"+(c||"")+"</div>";b.group=!0;var e=document.createElement("DIV");e.className="wgroupcontent";a.collapsed&&(e.style.display="none");a.height&&(e.style.height=LiteGUI.sizeToCSS(a.height));a.scrollable&&(e.style.overflow="auto");b.appendChild(e);var d=a.collapsed||!1,
f=b.querySelector(".wgroupheader");d&&f.classList.add("collapsed");f.addEventListener("click",function(a){var c=b.querySelector(".wgroupcontent").style;c.display="none"===c.display?"":"none";(d=!d)?f.classList.add("collapsed"):f.classList.remove("collapsed");a.preventDefault()});this.append(b,a);this.pushContainer(e);return b};Inspector.prototype.endGroup=function(){do this.popContainer();while(this._current_container&&!this._current_container.classList.contains("wgroupcontent"))};
Inspector.prototype.addTitle=function(c,a){a=this.processOptions(a);var b=document.createElement("DIV"),e="<span class='wtitle'><span class='text'>"+c+"</span>";a.help&&(e+="<span class='help'><div class='help-content'>"+a.help+"</div></span>");b.innerHTML=e+"</span>";b.setValue=function(a){this.querySelector(".text").innerHTML=a};this.row_number=0;this.append(b,a);return b};
Inspector.prototype.scrollTo=function(c){if(c=this.root.querySelector("#"+c))this.root.parentNode.parentNode.scrollTop=c.offsetTop-this.root.offsetTop};Inspector.prototype.processOptions=function(c){"function"==typeof c&&(c={callback:c});return c||{}};Inspector.prototype.processElement=function(c,a){a.callback_update&&c.setValue&&(c.on_update=function(){this.setValue(a.callback_update.call(this),!0)})};
Inspector.prototype.updateWidgets=function(){for(var c=0;c<this.widgets.length;++c){var a=this.widgets[c];if(a.on_update)a.on_update(a)}};Inspector.parseColor=function(c){return"<span style='color: #FAA'>"+c[0].toFixed(2)+"</span>,<span style='color: #AFA'>"+c[1].toFixed(2)+"</span>,<span style='color: #AAF'>"+c[2].toFixed(2)+"</span>"};LiteGUI.Inspector=Inspector;
